Router.match is not been called on every route change

前端 未结 1 1538
走了就别回头了
走了就别回头了 2021-01-23 08:00

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

相关标签:
1条回答
  • 2021-01-23 08:58

    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

    0 讨论(0)
提交回复
热议问题