我有一個使用嵌套路線反應路由器一個終極版的應用程序,如:如何確定活動路線反應路由器
<Provider store={store}>
<Router history={browserHistory}>
<Route name="sales" path="/" component={App}>
<IndexRoute name="home" component={Home} />
<Route name="reports" path="/reports" component={Reports}>
<IndexRoute name="reports-home" component={ReportsHome} />
<Route name="report-1" path="/reports/report-1" component={Report1}/>
<Route name="report-2" path="/reports/report-2" component={Report2}/>
</Route>
</Route>
</Router>
</Provider>
我想寫一個麪包屑成分;所以想要能夠遏制當前的路線。
我已經配置了部分使用所提供的withRouter函數接收路由器反應路由器:
Breadcrumbs = withRouter(Breadcrumbs);
這給了我一個路由器的對象,看起來像這樣:
Object {__v2_compatible__: true}
__v2_compatible__: true
createHref: createHref(location, query)
createKey: createKey()createLocation: createLocation(location)
createPath: createPath(location, query)
go: go(n)
goBack: goBack()
goForward: goForward()
isActive: isActive(location)
listen: listen(listener)
listenBefore: listenBefore(hook)
push: push(location)
pushState:()
registerTransitionHook: registerTransitionHook(hook)
replace: replace(location)
replaceState:()
setRouteLeaveHook: listenBeforeLeavingRoute(route, hook)
setState:()
transitionTo: transitionTo(nextLocation)
unregisterTransitionHook: unregisterTransitionHook(hook)
__proto__: Object
我可以用這個來確定當前的路線?有更好的方法嗎?
'isActive'可以被用於確定是否一個位置路徑名是有效或不 – Deadfish