Next js dynamic nested routes handling

57 Views Asked by At

I have a dynamic route that looks like this:
/programs/[country]/[state]/[id]

 -programs
    -[country]
     page.js
      -[state]
       page.js
         -[id]
          page.js

Dynamic segments are filled at request time.

normal routes look something like this:
/programs/Canada/federal/1
the problem is if I enter some route like this which country segment is invalid but [Id] is correct:

/programs/ldkflaksdjf/federal/1

the correct page still loads with no error.
how can I handle route segments so I can be sure user can't enter the wrong URL?

pages are server side and the fetch is called at the program folder level when user clicks on a specific program and navigates to this /programs/[country]/[state]/[id] URL.

0

There are 0 best solutions below