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

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


海绵宝宝撒
浏览 918回答 1
1回答

烙印99

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>
打开App,查看更多内容
随时随地看视频慕课网APP