gpt4 book ai didi

javascript - 每次路由更改时不会调用 Router.match

转载 作者:行者123 更新时间:2023-11-28 04:40:49 26 4
gpt4 key购买 nike

我有服务器端渲染应用程序并使用react-router进行路由。我之前使用的是 Router.Run ,因为该方法不再是我使用的 Router.Match 。以前,当路由发生变化时,router.run 会被调用,但行为相同router.match 中没有发生。这背后有什么原因吗?

最佳答案

我已经在下面定义的入口模块中定义了我的路由器,它将转到布局组件来查找路由路径:

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'));

布局组件会将router中定义的路径绑定(bind)到布局组件中的不同组件

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>
)

}
);

您可以为路线组件定义任何操作。它对我来说工作正常

关于javascript - 每次路由更改时不会调用 Router.match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43796916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com