Skip to content

<AbsoluteRoutes> #12959

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

Open
ryanflorence opened this issue Feb 5, 2025 · 2 comments
Open

<AbsoluteRoutes> #12959

ryanflorence opened this issue Feb 5, 2025 · 2 comments

Comments

@ryanflorence
Copy link
Member

ryanflorence commented Feb 5, 2025

In v5 deeply nested <Route path="/absolute/path"> matched the parent portion of the URL, but in v6 deeply nested <Routes> build upon the previous path and won't match an absolute path.

To facilitate easier migrations to v6 as well as allow people to have centralized route tables with absolute paths, you can use <AbsoluteRoutes> as a replace for <Routes>.

For example:

// High up the tree:

<Routes>
  <Route path="admin/*" />
</Routes>

// ✅ deeper in the tree uses relative paths that build on /admin/
<Routes>
  <Route path="users" />
  <Route path="settings" />
</Routes>

// ❌ does not work today
<Routes>
  <Route path="/admin/users" />
  <Route path="/admin/settings" />
</Routes>

// ✅ will work now with AbsoluteRoutes
<AbsoluteRoutes>
  <Route path="/admin/users" />
  <Route path="/admin/settings" />
</AbsoluteRoutes>

Again, this will facilitate migrations from v5 as well as allow folks to use centralized route tables:

const routes = {
  admin: "/admin/*",
  users: "/admin/users/:userId"
}

<Routes>
  <Route path={routes.admin} />
</Routes>

// and then inside the tree of the admin route
<AbsoluteRoutes>
  <Route path={routes.users} />
</AbsoluteRoutes>
@ryanflorence ryanflorence converted this from a draft issue Feb 5, 2025
@ivosabev
Copy link

ivosabev commented Feb 5, 2025

Instead of increasing the API surface with a new AbsoluteRoute, why not just make all routes absolute if starting with a /?

@ryanflorence
Copy link
Member Author

ryanflorence commented Feb 5, 2025

That's how it works when it's not a "descendent <Routes>". For example, this works fine:

      <Routes>
        <Route path="/" />
        <Route path="/admin">
          <Route path="/admin/users" />
        </Route>
      </Routes>

It's when it's rendered later.

Maybe we could change a bunch of the context internals, but this little component can be done w/o changing anything, in fact it could done in userland. Always a tradeoff, we'd rather not mess with how context/matching work when the behavior can be composed instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Planned
Development

No branches or pull requests

3 participants