Pretty URLs based on _id?

I have events and groups. As events belong to groups my url structure needs to be:
/group/event

eg:
/football/sunday-game

or:
/board-games/chess-tournament

At the moment the url segments are the _id fields provided by meteor. React Router can get this ID and knows which document to look up. So if ‘football’ has an id of 1000 and ‘sunday-game’ has an id of 2000 then my url is:
/1000/2000

This works but its ugly. I could use the title field to generate a nicer url but Im not sure if this can work with my approach of looking up document ids. This must be a common requirement so is there a standard pattern for solving this? Thanks

What you are looking for is commonly known as slug (aka SEO names). You generate the slug from the tille using for example the strman slugify function and then save it in the DB in the slug field. You index that field and then you can search for it like you do for an id.
That is the simple approach as long as you don’t allow same groups and events of the same name. Once you do you will need to add additional parts to your slug like date.

2 Likes

I just happen to build a football application myself. Nive! :slight_smile:.

The way i’m solving it is to generate a so called slug per match. This slug looks like this:

/matches/24-03-2017/zcfc-1-vs-hbok-1

The date helps to make the match name unique and it makes that the name is always that name at that point in time. (Club and team names change over time).