React Router
React Router
2021/08/12 (新增連結)
Route
How to Get Started With React Router, In-Depth Explanation With Project
NavLink
React Router Architecture That’s Simple, Scalable, and Protected
How to Use URL Parameters and Query Strings With React Router
Define Routes That Accept URL Parameters, and Get Them
Get and Set Query Strings
How To Pass Multiple Route Parameters in a React URL Path
React Routes and Route Parameters
Code Splitting by Routes and Components in React
Route-based splitting
Component-based splitting
Routing and Code Splitting in React: Proper implementation of React Router with React.lazy() and Suspense
Routing and Component level code splitting with React
Router Level Code Splitting
Component Level Code Splitting
Lesser-known features of React-Router
Prompt
MemoryRouter
StaticRouter
generatePath
Protect Your Route With ProtectedRoute and Guards in ReactJS
Dynamic routing
React Router v6
React Router v6 in Three Minutes: Learn what’s coming in the latest alpha
Switch to Routes
Nested and Relative Routes With Automatic Route Matching
Relative Links
Descendant Routes
useRoutes
useNavigate Instead of useHistory
A Sneak Peek at React Router v6
<Switch> is becoming <Routes>
Big Changes with <Route>
The component/render prop will be substituted for the element prop
Nested Routes are Simpler
useNavigate Instead of useHistory
From 20kb to 8kb
<Routes> is the new <Switch>
<Route component> is replaced with <Route element>
No more exact and strict props
Relative paths and links
Easier Nested Routes
Future-ready useNavigate instead of useHistory
Bundle size — 28.4 kB to 10.2 kB
Routes Replaces Switch
Routes and Links are relative to their parent
Object-based routes
useRouter
Smaller Bundle Size
Suspense Ready Navigation
useNavigate
React Router v5
Dynamically Loading Material-UI Icons Using React Router Query Params
其實並沒有大幅的更新,是因為技術上的理由,使得原本是4.4,卻被迫跳到5.0
useParams
useLocation
useHistory
useRouteMatch
// before
function BlogPost({ match, location, history }) {
let { slug } = match.params
// ...
}
// after
function BlogPost() {
let { slug } = useParams()
let location = useLocation()
let history = useHistory()
// ...
}
React Router v4
Basic intro to React Router v4
<BrowserRouter>
<Route>
<Link>
Beginner’s Guide to React Router 4
react-router-demos (source code)
#1 Basic routing
#2 Nested routing
#3 Nested routing with path parameters
#4 Protected path routing
Deep dive into React Router
Different types of routers in react router
MemoryRouter
HashRouter
BrowserRouter
Role based authorization in React
with router & higher-order component
Simple Authorization
Conditional Routes
How to Build a Website with React, React Router & Styled-Components
The Love-Hate Relationship between React Router and React Components
How to handle routing and navigation in React JS
Installation
Configuring the routes
Configuring history
Everything is a component in React-Router
Different Routers for Different Environments
Lock-in to Router Specific View Components
Integration with React-Redux
Major Breaking Changes
Async
Async React using React Router & Suspense
The Asynchronous (lazy) Way
Asynchronous React Router
** There’s currently an issue with react-router v4.4.0 where it doesn’t handle the case of a lazy-loaded or memoized component passed in through the component prop on Route.
Hooks
Implementing private routes with React Router and Hooks
Initial setup
Providing the auth data to the components
Defining private routes
How to restrict your Routes and Links in React.js now with Hooks
Restricting Routes
Restricting Links
Nested routes
Private route / Authenticated routes
Redux & Router
Using Cookies with React, Redux and React Router 4
react-cookie
Implementing redux and react-router v4 in your react app (part 2)
猴子也能看懂的 React 教學 - 4 - 從 React 走向框架,把後端移到前端
React router & Redux
React Router v3
Reach Router
React Location
Introduction to React Location : A Modern React Router with Async Routing and More Features