Making NextJS make difference between /products/[number].js & /products/[string].js
Unanswered
Californian posted this in #help-forum
CalifornianOP
I've got a product configurator living in /products/123 path. I can't change the path of it for external reasons. Product's ID is always a number.
Also I want to create a "trait" discovery page for products which would use a slug as a name, which is never an integer. For example /products/black.
Of course it doesn't work so far because NextJS considers both of the paths to be the same one.
I don't want to bundle both of these pages' logic into one file eg. /products/[id_or_trait].js because it would turn into ape sh*t real fast.
Is there any way to achieve that? Has anyone tried before?
Also I want to create a "trait" discovery page for products which would use a slug as a name, which is never an integer. For example /products/black.
Of course it doesn't work so far because NextJS considers both of the paths to be the same one.
I don't want to bundle both of these pages' logic into one file eg. /products/[id_or_trait].js because it would turn into ape sh*t real fast.
Is there any way to achieve that? Has anyone tried before?
1 Reply
@Californian I've got a product configurator living in /products/123 path. I can't change the path of it for external reasons. Product's ID is always a number.
Also I want to create a "trait" discovery page for products which would use a slug as a name, which is never an integer. For example /products/black.
Of course it doesn't work so far because NextJS considers both of the paths to be the same one.
I don't want to bundle both of these pages' logic into one file eg. /products/[id_or_trait].js because it would turn into ape sh*t real fast.
Is there any way to achieve that? Has anyone tried before?
You cannot have two dynamic segments at the same level.
If I was you, I would make /products/id/[id] and /products/slug/[slug] (or something similar), then redirect/rewrite /products/:foo to either /products/id/:foo or /products/slug/:foo depending on the value of foo
If I was you, I would make /products/id/[id] and /products/slug/[slug] (or something similar), then redirect/rewrite /products/:foo to either /products/id/:foo or /products/slug/:foo depending on the value of foo