简体   繁体   English

将道具传递给路由器,使用 redux 和 react-router

[英]Passing props to router, using redux and react-router

I'm trying to set up the router in my app using redux and stateless components.我正在尝试使用 redux 和无状态组件在我的应用程序中设置路由器。

Here I have my routes.jsx file:这里我有我的routes.jsx文件:

const TodoApp = (props) => {
    return (
        <div>
            {props.children}
            <Footer />
        </div>
    )
};

export default (
    <Route  component={TodoApp}>
        <Route path='/' component={TodoList} />
    </Route>
);

First of all, props.children is not working.首先, props.children不起作用。 I don't know what's wrong in there.我不知道里面有什么问题。

Of course, I have my AppRoot.jsx :当然,我有我的AppRoot.jsx

export default (
    <Provider store={store}>
        <Router history={history}>
            {routes}
        </Router>
    </Provider>
)

where {routes} are the routes above.其中{routes}是上面的路线。 What I'm actually trying to do here is to have a kind of template where the footer (and navbar, or whatever) is always there, and then I change the props.children with whatever is on the route (TodoList in this example.)我实际上在这里尝试做的是有一种模板,其中页脚(和导航栏或其他任何东西)始终在那里,然后我将props.children更改为props.children上的任何内容(在此示例中为 TodoList。 )

Try to export component function instead of instance in routes.jsx尝试在routes.jsx中导出组件函数而不是实例

export default () => (
    <Route component={TodoApp}>
        <Route path='/' component={TodoList} />
    </Route>
);

and AppRoot.jsx :AppRoot.jsx

export default () => (
    <Provider store={store}>
        <Router history={history}>
            {routes}
        </Router>
    </Provider>
);

For complete examples take a look here: https://github.com/reactjs/react-router-redux有关完整示例,请查看此处: https : //github.com/reactjs/react-router-redux

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM