React Router paths

Hello there.

I was following a tutorial and found myself stuck because I saw the following piece code:

if (!user) {
          return (
            <Redirect
              to={{
                pathname: 'signin',
                state: { from: location },
              }}
            />
          );
        }

This one is React Router v5. Mine is v6 (I use Navigate instead).

I don´t understand how is possible that this piece works:

pathname: 'signin'

I cannot make this work without without slash ("/signin"), variables (with slash) or passing props… And I am wondering how can someone make this work.
I was checking the documents for React Router and all examples contain slashes, but then I´ve seen more code online where they don´t use it.

Does anyone know why?

If I remember correctly then pathname without slash will be added to the current path, but pathname with a slash to the root.
But I may be completely wrong, haven’t used ReactRouter for a while.

That’s right, but someonehow in the tutorial the guy made it work, without slashes and was not being added in the current path, which was driving me crazy…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.