URL aliases in Meteor

Has anybody come up with a way to provide URL aliases for dynamic content? I am currently (still) using Iron Router and am following the usual pattern of defining my routes with a slug determined by a mongo _id.

Lets say I have /business/view/:id as my route, how could I implement /business/v/business_name without needing to rewrite/duplicate my entire logic? Also, if a business had an alias, and I access /business/view/:id, the browser should display /business/v/business_name instead

Are there any patterns out there that allow dealing with document.location like that?

I know this is an ancient thread, but I’d really like to see something like this…I’ve been looking around and haven’t found anything.

I solved it by providing a different route for vanity urls like /biz/:vanity and then store the actual vanity url with the business. I check the uniqness before writing the vanity url and do a simple redirect in the router when accessing /business/view/:id if a business has a vanity url.

yeah, I was leaning in that direction. I thought additionally of creating a separate collection for aliases that maps the vanity url (or urls) to actual routes. On the target document save i would update the vanity url collection as needed.

thanks for the feedback and excuse the necrobump.

:laughing: :rofl: :joy:

I think the best way is to slugify the org/biz or user name. NPM is available for that otherwise I can give you a proper code. Have an index on the slug field in the Users or Organizations/Businesses collection and your route would look like /biz/:slug with a call on Businesses.findOne({ slug }) and url would look like https://www.website.com/biz/dancing-in-the-rain