不会在每次路由更改时调用 Router.match [英] Router.match is not been called on every route change

查看:43
本文介绍了不会在每次路由更改时调用 Router.match的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有服务器端渲染应用程序并使用 react-router 进行路由.我使用的是 Router.Run 之前因为该方法不再使用我使用 Router.Match.Previously 当有路由更改 router.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 组件会将router 中定义的路径绑定到Layout Component 中的不同组件

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆