10. Advanced Routing Techniques: Special Cases
Activity 10.01: Creating Authentication Using Routing Techniques
Solution:
Note
The code for this activity can be found here: https://packt.live/3bAUFrz.
Let's implement the tasks one by one:
- Create a new React app:
$ npx create-react-app [name]
- Go to the
src/App.js
file, deletelogo.svg
andApp.css
, and clear out the contents ofApp.js
. - Inside
App.js
, create a new React functional component calledApp
. - Install the required dependencies:
$ npm install formik react-router-dom
- Create a 404 page. Using what we have learned about
404
pages, we will define our main application with one route:import React from 'react'; import { Â Â BrowserRouter as Router, Â Â Route, Â Â Switch, Â Â Redirect, Â Â useLocation } from 'react-router-dom'; import './App.css'; function App() { Â Â return ( Â Â Â Â <div className=...