Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Wrong nested path rendered in v6.0.0-beta.1 #7948

Closed
liho98 opened this issue Aug 14, 2021 · 5 comments
Closed

[Bug]: Wrong nested path rendered in v6.0.0-beta.1 #7948

liho98 opened this issue Aug 14, 2021 · 5 comments
Labels

Comments

@liho98
Copy link

liho98 commented Aug 14, 2021

What version of React Router are you using?

v6.0.0-beta.1

Steps to Reproduce

Codesandbox link: https://codesandbox.io/s/dreamy-cookies-1z1og

function AuthRoutes() {
  return useRoutes([
  {
    path: "login",
    element: lazy(() => import("./views/Auth/Login")),
  },
  {
    path: "forget-password",
    element: lazy(() => import("./views/Auth/ForgetPassword")),
  },
])
}

// forget-password.jsx

  <Link to="/auth/login"> // in dom got rendered as /auth/auth/login
   Login
  </Link>

image

       <Route path="auth/*" element={<AuthLayout />}>
            <Route path="*" element={<AuthRoutes />} />
          </Route>

Expected Behavior

it should behave as v6.0.0-beta.0, the correct should be render as /auth/login.

I think its a bug on the latest build without proper checking on nested path rendering.

Actual Behavior

The nested paths are rendered with concatenating parent path with absolute path which is incorrect , the result rendered is /auth/auth/login
Using Link component or useNavigation both returning wrong nested path.

Solution now is fallback to v6.0.0-beta.0

@liho98 liho98 changed the title [Bug]: Wrong path rendered in beta v6.0.0-beta.1 [Bug]: Wrong nested path rendered in beta v6.0.0-beta.1 Aug 14, 2021
@liho98 liho98 changed the title [Bug]: Wrong nested path rendered in beta v6.0.0-beta.1 [Bug]: Wrong nested path rendered in v6.0.0-beta.1 Aug 14, 2021
@thedanwoods
Copy link

Same issue here - everything in <Link /> or useNavigate() is suddenly being treated as a relative path, which makes v6.0.0-beta.1 unusable for us. It works fine in v6.0.0-beta.0.

@jgoux
Copy link

jgoux commented Aug 16, 2021

The issue seems to be that a basename is set in RouteContext, even if not explicitly provided by the user :

https://codesandbox.io/s/async-tdd-yvgk8?file=/src/Login.jsx (see the console)

Here :

basename = basename ? joinPaths([parentPathname, basename]) : parentPathname;

I don't think parentPathname should be provided as a fallback value for basename.

@wojtekmaj
Copy link

I think I have related issue.

I have a bunch of nested routes. In /form/, I have something along the lines

    <Routes>
      {paths.map((path) => (
        <Route
          key={path}
          path={path}
          element={<p>Step {path}</p>}
        />
      ))}
      <Route path="*" element={<Navigate to={resolvedPaths[0]} />} />
    </Routes>

where

paths = ['1', '2', '3']
resolvedPaths = ['/form/1', '/form/2', '/form/3']

so that when you enter /form you're automatically redirected to /form/1.

When updating from 6.0.0-beta.0 to 6.0.0-beta.1, this stopped working, and redirected me to /form/form/1 instead. navigate() has the same problem.

@nmarchais
Copy link

Same issue for me...

@chaance
Copy link
Collaborator

chaance commented Aug 20, 2021

Fixed in #7961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants