-
Notifications
You must be signed in to change notification settings - Fork 0
Add Routing and Navigation
- "Routing" is a term for when the form of the application is affected by the URL bar.
-
react-routerdetermines which React component to display based on URL. - Good use of routing allows a lot of information to be codified in URL.
React Router will add routing capabilities for our app. Add react-router-dom which is a subset of React Router that is used in the browser:
NOTE: React router is at v6 as of 2022. Many commands have changed. If you have problems refer to the official documentation https://reactrouter.com/docs/en/v6. It is still possible to use v5 with the following documentation https://v5.reactrouter.com/web/guides/quick-start.
# react-router-dom@4.3.1 (at the time of the demo)
$ npm install react-router-dom --saveNOTE: in the original version,
historywas also installed but it seems deprecated. The command used wasnpm install --save history@4.7.2. The method imported from the library was createBrowserHistory which helped React Router to determine what the object is and what it was in the past.
Update Main.jsx to import BrowserRouter and Route:
- We also add a
Navigationcomponent. TheNavigationcomponent imports Link fromreact-router-domto navigate through the app. Refer to the code project for more info.
import React from 'react';
import { Provider } from 'react-redux';
import { store } from '../store';
import { ConnectedDashboard } from './Dashboard';
import { BrowserRouter, Route, } from 'react-router-dom';
import { ConnectedNavigation } from './Navigation';
export const Main = ()=> (
<BrowserRouter>
<Provider store={store}>
<div className="container mt-3">
<ConnectedNavigation/>
{/*<ConnectedDashboard/>*/}
<Route
exact
path="/dashboard"
render={ () => (<ConnectedDashboard/>)}
/>
</div>
</Provider>
</BrowserRouter>
)2022 ModokemDev
-
Express-react-app
- Security Considerations
- Webpack setup
- Add Redux
- Add Routing and Navigation
- Add Sagas
- Creating Persistent Data storage with Node, Express, and MongoDB