安装react-router

npm add react-router-dom

1、在components中建立两个组件;

image-20211104175520976

内容:

About:

image-20211104175610456

Home:

image-20211104175630295

2、在app.jsx中:

image-20211104175931642

image-20211104172439324

应该使用BrowserRouter包裹着App.jsx

所以:在app.jsx中可以不使用BrowserRouter,在index.js文件中将App组件包裹着:

image-20211104180138278

路由