Suppose, I want to take params region
and lang
in URLs like:
https://root.com/{region}/{lang}
https://root.com/{region}/{lang}/school
How do I do that? I tried Dynamic Routing, but it doesn’t seem to work with the root index.js. How should I structure my folder tree?
/pages/[region]/[lang]/index.js
Doesn’t look like a valid one.
2
Answers
In your default exported component in
/pages/[region]/[lang]/index.js
you can use next/router – useRouter.The query object will contain the
region
andlang
parameters.to get the
/school
path simply add a school.js file in the same folder asindex.js
and get query params with useRouter as above.Hey I believe there are couple ways,
Use dynamic routing for URLs like https://root.com/{region}/{lang}.