1 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊
react實(shí)現(xiàn)路由可以直接使用react-router。
ReactRouter是由Ryan Florence開發(fā)的應(yīng)用于ReactJS的路由組件,它通過定義ReactJS組件<Routes>及相關(guān)子組件來實(shí)現(xiàn)頁(yè)面路由的映射、參數(shù)的解析和傳遞。
以下是例子:
var ReactRouter = require('react-router');
var Routes = ReactRouter.Routes;
var Route = ReactRouter.Route;
//定義整個(gè)頁(yè)面的路由結(jié)構(gòu)
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>組件會(huì)直接跳轉(zhuǎn)到目標(biāo)位置。from 屬性僅用于<redirect>包裹著<Switch> 組件中的時(shí)候。
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 該組件發(fā)生跳轉(zhuǎn)
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>
- 1 回答
- 0 關(guān)注
- 934 瀏覽
添加回答
舉報(bào)