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

X1034 react router upgrade to 6.0 #400

Merged
merged 13 commits into from
Sep 15, 2023
Merged

Conversation

seenanair
Copy link
Contributor

@seenanair seenanair commented Sep 12, 2023

react-router-dom updated from v5 to v6.15

Following are the main changes

  • Prompt deprecated in v6 instead used a third-party library. react-router-prompt

  • Major changes in route switching

    • Switch doesn't exist
    • Routes.tsx file removed and new file ‘RouteLayout.tsx’ added
    • Replaced with createBrowderRouter function
    • Route change in props
    • Custom Route components aren't valid in react-router-dom@6 like what was commonly used in v5, they are replaced
      with a wrapper component pattern which uses Outlet
        - Replaced AuthRoute with AuthLayout
       
  • Redirect replaced with

  •  NavLink property ‘exact renamed to ‘end’

  •   useNavigate instead of useHistory

  • history.push replaced by navigate
    -  Link props change 
    -  NavLink - activeClassName and activeStyle props removed from NavlinkProps. Instead a function required to return either style or className that will allow you to customize the inline styling or the class string based on component’s active state

  • RouteComponentProps doesn't exist in v6

    • RouteComponentProps changed to useSearchParams instead of match
    • RouteComponentProps, StaticContext,LocationState replaced with useLocation i to access the redirected page state
  •   navigate(0) to reset the current page

  • Logout changed as a jsx element. All component children of Routes must be a Route or React.Fragment

  • Use loader and useLoaderData instead of DataFetcher if need to access query params before loading page (e.g FileManager, LocationByBarcode)

Reference for Migration from v5 to v6
https://reactrouter.com/en/main/upgrading/v5#upgrade-to-react-router-v51
 

Copy link
Contributor

@khelwood khelwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very thorough. I have some questions just for understanding.

src/components/AppShell.tsx Outdated Show resolved Hide resolved
src/components/AppShell.tsx Show resolved Hide resolved
src/components/LocationSearch.tsx Show resolved Hide resolved
src/components/nav/index.tsx Show resolved Hide resolved
src/pages/Store.tsx Show resolved Hide resolved
src/pages/Store.tsx Outdated Show resolved Hide resolved
@seenanair seenanair requested a review from khelwood September 13, 2023 08:56
Copy link
Contributor

@khelwood khelwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you answer my questions from the last review please?

@seenanair
Copy link
Contributor Author

seenanair commented Sep 13, 2023

Can you answer my questions from the last review please?

@khelwood I have answered and made changes as well yesterday. I can see my comments above. If you can't please let me know

@seenanair seenanair merged commit 920c9e5 into devel Sep 15, 2023
7 checks passed
@sabrine33 sabrine33 deleted the x1034_react_router_upgrade branch December 18, 2024 16:58
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 this pull request may close these issues.

2 participants