index.jsApp.js index.jsimportReactfrom‘react’; importReactDOMfrom‘react-dom’; importAppfrom‘./App’ import { HashRouter } from‘react-router-dom’ ReactDOM.render( <React.StrictMode> <HashRouter><App/></HashRouter> </React.StrictMode>, document.getElementById(‘root’) ); App.js/** * react-router-dom 需要安装npm i react-router-dom —save * HashRouter: 开启路由 ** Link:to 属性指定跳转的链接 Route: path component **语法发生变化,Route 需要在 Routes 里,组件为 element,注意括号内为标签,Switch 重命名为 Routes */ importReact, { Component } from‘react’ import {Link,Route,Routes} from‘react-router-dom’ importHomefrom‘./components/home’ importListfrom‘./components/list’ classAppextendsComponent { render() { return ( <div> <div> <Linkto=“/home”>shouye</Link> <Linkto=“/list”>liebiaoye</Link> </div> <div> <Routes> <Routepath=“/“element={<Home/>}exact/> <Routepath=“/home”element={<Home/>}/> <Routepath=“/list”element={<List/>}/> </Routes> </div> </div> ) } } exportdefaultApp