react-router 4.0这个路由怎么配置

2025-05-09 19:31:57
推荐回答(1个)
回答1:

react实现路由可以直接使用react-router。
ReactRouter是由Ryan Florence开发的应用于ReactJS的路由组件,它通过定义ReactJS组件及相关子组件来实现页面路由的映射、参数的解析和传递。
以下是例子:
var ReactRouter = require('react-router');
var Routes = ReactRouter.Routes;
var Route = ReactRouter.Route;

//定义整个页面的路由结构
var routes = (






);
与之前版本不同,在 react-router4 中,渲染组件会直接跳转到目标位置。from 属性仅用于包裹着 组件中的时候。
Rendering a will navigate to a new location. The new location will override the current location in the history stack, like server-side redirects (HTTP 3xx) do
// render 该组件发生跳转

From: A pathname to redirect from. This can only be used to match a location when rendering a inside of a . See for more details.