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

Upgrade react-router-dom to v6 #1945

Closed
louischan-oursky opened this issue Mar 31, 2022 · 1 comment · Fixed by #2117
Closed

Upgrade react-router-dom to v6 #1945

louischan-oursky opened this issue Mar 31, 2022 · 1 comment · Fixed by #2117
Assignees

Comments

@louischan-oursky
Copy link
Collaborator

louischan-oursky commented Mar 31, 2022

react-router-dom@6 has been released. We are still using one of the beta version.

useBlocker was removed in v6.0.0-beta.7 and still does not come back as of 2022-05-20.

There is a bug issue regarding the * routes with the <a href> tag (remix-run/react-router#8086) and it is fixed in v6.0.0-beta7 (https://github.com/remix-run/react-router/releases/tag/v6.0.0-beta.7).

So, this issue will not be solved at this moment.

@andychow326
Copy link
Contributor

andychow326 commented May 20, 2022

Estimate: 2hr

BrowserRouter

  • no special change

Routes

  • no special change

Route

The default Route element is an Outlet (https://reactrouter.com/docs/en/v6/components/outlet). This means the route will still render its children even without an explicit element prop, so you can nest route paths without nesting UI around the child route elements.

  • react-router-dom v6 introduced nest route element, for example:

Original:

<Route path="/users/" element={<UsersScreen />} />
<Route path="/users/add-user/" element={<AddUserScreen />} />
<Route
  path="/users/:userID/"
  element={<Navigate to="details/" replace={true} />}
/>
<Route
  path="/users/:userID/details/"
  element={<UserDetailsScreen />}
/>
<Route
  path="/users/:userID/details/add-email"
  element={<AddEmailScreen />}
/>

New version:

<Route path="users">
  <Route path="/" element={<UsersScreen />} />
  <Route path="add-user" element={<AddUserScreen />} />
  <Route path=":userID" element={<Navigate to="details/" replace={true} />}>
    <Route path="details" element={<UserDetailsScreen />}>
      <Route path="add-email" element={<AddEmailScreen />} />
    </Route>
  </Route>
</Route>

Link

  • need to import from "react-router-dom" rather than "react-router"

Navigate

  • no special change

useParams

  • no special change

useSearchParams

  • no special change

useNavigate

  • need to import from "react-router-dom" rather than "react-router"

useHref

  • need to import from "react-router-dom" rather than "react-router"

useBlocker

  • removed since v6.0.2

useLocation

  • need to import from "react-router-dom" rather than "react-router"

useResolvedPath

  • need to import from "react-router-dom" rather than "react-router"

@louischan-oursky louischan-oursky changed the title Upgrade react-router-dom to v6 Upgrade react-router-dom to v6.0.0-beta.6 May 20, 2022
@andychow326 andychow326 changed the title Upgrade react-router-dom to v6.0.0-beta.6 Upgrade react-router-dom to v6 May 23, 2022
@andychow326 andychow326 linked a pull request Jun 16, 2022 that will close this issue
louischan-oursky added a commit that referenced this issue Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants