为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

海绵宝宝撒 2018-12-03 04:04:42
react-router 4.0这个路由怎么配置
查看完整描述

1 回答

?
烙印99

TA贡献1829条经验 获得超13个赞

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

//定义整个页面的路由结构
var routes = (
<Routes location="hash">
<Route path="/" handler={App}>
<Route path="books" name="bookList" handler={Books}/>
<Route path="movies" name="movieList" handler={Movies}/>
</Route>
</Routes>
);
与之前版本不同,在 react-router4 中,渲染<redirect>组件会直接跳转到目标位置。from 属性仅用于<redirect>包裹着<Switch> 组件中的时候。
Rendering a <Redirect> 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
<Redirect to="/somewhere/else"/> // render 该组件发生跳转

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

<Switch>
<Redirect from='/old-path' to='/new-path'/>
<Route path='/new-path' component={Place}/>
</Switch>



查看完整回答
反对 回复 2018-12-20
  • 1 回答
  • 0 关注
  • 888 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信