每次路由更改时都没有调用Router.match [英] Router.match is not been called on every route change
问题描述
我有服务器端渲染应用程序并使用react-router进行路由。我正在使用 Router.Run 之前因为方法不再使用 Router.Match 。以前当路由更改时路由器.run曾经被调用但是行为相同在router.match中没有发生。背后有什么理由吗?
I have server side rendering app and using react-router for routing. I was using Router.Run Before as the method is no more I am using Router.Match.Previously when there was route change router.run used to be called but same behavior is not happening in the router.match. Is there any reason behind it?
推荐答案
我在下面定义的入口模块中定义了我的路由器,它将转到布局组件寻找路径路径:
I have defined my router in entry module defined below and it will go to Layout component to look for route paths:
import { Router, Route, IndexRoute, hashHistory } from "react-router";
ReactDOM.render(
<Router history={hashHistory}>
<Route path="/" component={Layout}>
//<IndexRoute component={Featured}></IndexRoute>
<Route path="archives" name="archives" component={Archives}></Route>
<Route path="settings" component={Settings}></Route>
<Route path="featured" component={Featured}></Route>
</Route>
</Router>,
document.getElementById('app'));
布局组件将路由器中定义的路径绑定到布局组件中的不同组件
Layout component will bind the path defined in router to different components in Layout Component
import { Link } from "react-router";
class Layout extends React.Component(
render(){
return(
{this.props.children}
<li><MenuItem><Link to="archives">archives</Link></MenuItem></li>
<li><MenuItem><Link to="settings">settings</Link></MenuItem></li>
<li><MenuItem><Link to="featured">featured</Link></MenuItem></li>
)
}
);
您可以为您的路线组件定义任何操作。对我来说工作正常
You can define any action for your route components.its working fine for me
这篇关于每次路由更改时都没有调用Router.match的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!