Change the order to
/student/id/grades
/student/id
The error happens because route searching happens in the order in which you list them.
For eg. say you have two routes as follows:
/a/b
and /a/
Let's consider two cases -
Order 1
/a/
/a/b/
Now if you search for /a/<some id>
then it matches the first route and you are routed accordingly. Again, when you search for /a/b/<some id>
, the prefix i.e. /a/
matches again and you are routed to the first route.
Order 2-
/a/b/
/a/
Now, if you search for /a/<some id>
then it does not match the first route (as the prefix /a/b/
does not match). But the second route matches and you are routed accordingly.As an alternative, if you search for /a/b/<some id>
then the first route matches. And then you are routed to the correct URL.
As a rule of thumb, remember to put the more particular case first.