ReactJS - react-router nested path not rendered

怎甘沉沦 提交于 2019-12-11 10:14:05

问题


I can't solve this problem, I can't render the HTML of my component that i call from a nested path like /page/detail

My route tree

render(
    (<Router history={history}>
        <Route path="/" component={App}>
            <IndexRoute component={Index}/>
            <Route path="page" component={Page}>
                <Route path="/page/detail" component={Detail} />
            </Route>
        </Route>
    </Router>),
    document.getElementById('main')
)

My {App} component renders this:

render() {
    return (
        <div>
            <nav className="navbar">
                <ul className="nav navbar-nav navbar-right">
                    <li><Link className="menu-link" ref="menu" to="/page">Page Test</Link></li>
                </ul>
            </nav>
            <div id="content-wrapper">{this.props.children}</div>
        </div>
    )
}

My route /page/detail is called from a Link inside the component {Page} but if i access to this link i see only what {Page} component renders. I've searched for some solution about nested routes with react-routers but i didn't find an answer.

UPDATE:

By this solution i've rendered my {Detail} component's html: I've inserted this within {Page} component

{this.props.children || <div>My Detail page</div> }

UPDATE 2

In my {Page} component I've inserted a jQuery plugin.

mix() {
    $("#filter-gallery").mixItUp();
}

destroy() {
    $('#filter-gallery').mixItUp('destroy');
}

componentDidMount() {
    this.mix();
}

componentWillUnmount() {
    this.destroy();
}

This plugin works only at {Page} refresh page, if i navigate to /page/detail and then come back to /page the plugin doesn't work.


回答1:


I've find a solution by setting routes in this way:

<Route path="studio" component={Studio} />
    <Route path="studio/detail" component={Calendar} />


来源:https://stackoverflow.com/questions/33649322/reactjs-react-router-nested-path-not-rendered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!