1

I created a nextJS application and using its routing system there. Now I have created a dynamic route to catch a URL like {base_url}/{username}/{post-slug}. But it is also capturing {base_url}/post/create which I want to be rendered on different page. So is there anything available in nextJS route to match a URL absolutely? Like, exact in react router? Or do I have to redirect user from getInitialProps function in nextJS?

2
  • Check the document content using the keyword Regular expression may help Commented Feb 20, 2020 at 7:02
  • Sorry to bother you, but I can't find any reference for regexp in the routing documentation of the next js. Commented Feb 20, 2020 at 7:08

1 Answer 1

1

I created sample codesandbox for this question.

It works without Regular Expression. Always the specific route (post/create) has the priority.
I hope this helps you.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh... I'm sorry I misunderstood your question. This is not a direct anwer but, I think the structure of your user route should be {base_url}/user/{username}/{post-slug}. This matches http://yourhostname/user/{username}/{post-slug} and doesn't conflict the post route.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.