ReactRouter V6

Tram Ho

  1. Overview
  2. Bundles
  3. Routers
  4. Suspense
  5. Outlet
  6. Conclude

1. Overview

React route is a route router to your pages, helping to synchronize the appearance and urls of your web pages. Currently React route has released V6 betas, with changes and improvements we will find out.

2. Bundles

With version 6, the size is 62% smaller, making your package download speed significantly faster. With version 6 download speed is 5ms with 4G and 80ms for 3G compared to its predecessor package v5, 11ms with 4G and 190ms with 3G.

  • This is help for package size.
  • Not supported for versions older than IE11
  • Does not support React with version less than 16.8
  • Using Google Closure Compiler

And now let’s take a look at some of the upgraded APIs in this V6.

3. Routers

Instead of using <Switch></Switch> then use <Route path=”…”/> In V5 you have to create a parent Route and from the parent Route wrap the child Route. To Link to the child Route in the menu, you must match the parent Route and connect the child Route.

In V6 Route and Link automatically connect to its parent Routes

4. Suspense

Instead of accessing history to navigate the route, V6 provides useNavigate(), which is very useful after you perform an action such as submit login.

5. Outlet

Outlet is like props children, it will find components of child Route and put it in its place.

Depending on the url, <Outlet/> in Profile component will show component of MyProfile or OthersProfile

6. Conclude

So, I have learned briefly about React router V6. With significant improvements in package size as well as advanced features, are you looking forward to this V6 version? Finally, I wish you all a productive day.

Share the news now

Source : Viblo