添加 Router
Create React App 没有规定具体的路由解决方案,但 React Router 是最流行的一种。
¥Create React App doesn't prescribe a specific routing solution, but React Router is the most popular one.
要添加它,请运行:
¥To add it, run:
npm install react-router-dom
或者你可以使用 yarn
:
¥Alternatively you may use yarn
:
yarn add react-router-dom
要尝试它,请删除 src/App.js
中的所有代码并将其替换为其网站上的任何示例。基本示例 是一个很好的起点。有关添加路由的更多信息,请查看 关于添加路由的 React Router 文档。
¥To try it, delete all the code in src/App.js
and replace it with any of the examples on its website. The Basic Example is a good place to get started. For more info on adding routes, check out the React Router docs on adding routes.
在部署你的应用之前请注意 你可能需要配置生产服务器以支持客户端路由。
¥Note that you may need to configure your production server to support client-side routing before deploying your app.