I have a path="users/:userNickname"
, which works fine for anything like users/.mary
users/mary.kim
, but if the path is users/.
, it will redirect to 404 page even without sending request to the server. I feel like I’m missing something fundamental. Hope for directions.
2
Answers
For dynamic routes the React Router Dom library will be expecting more than a literal character.
React Router Dom can have a specific path such as
In React-Router
"."
and".."
are kind of "special" characters that are not literally interpreted when used as a link target path.See Link for details.
An earlier version of the docs mention both
"."
and".."
. These are often used when building relative paths where you want to navigate to a target path relative to the currently matched route.Imagine the following routing structure:
And the current URL path is:
"/foo/123"
Foo
to="./456"
, which is same as justto="456"
FooItem
to="../456"
Foo
to="../bar/123"
FooItem
to="../../bar/123"
This is all to say that when you are attempting to navigate to
"users/."
this is exactly the same as targeting"users/"
and if you are not rendering any route forpath="/user"
specifically then your 404 "catch-all" route is matched, of if you’ve not even that you’ll likely see the "no routes matched …" error.