Next-routes: Removing extra params from routes

Created on 11 Oct 2018  路  6Comments  路  Source: fridays/next-routes

Sorry to use GH as support board but I've been dealing with this problems for hours now.

Lets say I have something like:

<Link
  route="my-route"
  params={{ slug: item.slug, id: item.id }}
  passHref
>
...

.add('my-route', '/my-route/:slug/', 'my-route/XYZ')

What is the correct way to remove item.id from on the final route? On my case it will render something like http://0.0.0.0:4000/my-route/nice-slug/?id=26 I dont want to display ?id=26

Any ideas?

Most helpful comment

I have the same question

All 6 comments

I have the same question

Did any of you guys happen to find a solution?

Not sure I understand, why do you pass item.id if you don't need it in the url? Could you just use the slug to look up the content in the database?

I have the same issue and would love a solution.

Not sure I understand, why do you pass item.id if you don't need it in the url? Could you just use the slug to look up the content in the database?

Indeed, I ended up using slug only.

My personal use-case at the time of asking was: I did not have access to the back-end API, and the slug was not unique in the database (i.e. a few rows could have the same slug). So, I needed both a slug (to look nice in the URL bar) and an ID (to fetch the correct item). Obviously not a great idea, but those were the days. Later, I was given access to the API later and updated it to generate unique slugs - no ID needed now.

Glad to hear you got it working. Another way would be to keep the id in the url with a route like /my-route/:id/:slug. Depending on the database system and indexing, it can be faster to lookup by id.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arefaslani picture arefaslani  路  3Comments

bliitzkrieg picture bliitzkrieg  路  4Comments

jchiellini picture jchiellini  路  4Comments

apapacy picture apapacy  路  4Comments

nishtacular picture nishtacular  路  3Comments