我最近使用React-router,發現它並不那麼直觀。 這是我的情況。我定義了一個無狀態的React組件「MainLayout」,它有兩個參數來包含「headerBar」組件和「children」組件。如何在react-router中指定組件的參數?
mainlayout.js:
const MainLayout = ({children,headerBar})=>{
return (
<div className="app">
{headerBar}
<main>
{children}
</main>
</div>
);
}
export default MainLayout;
我的路線是這樣的:
routes.js:
export default (
<Router history={browserHistory}>
<Route component={MainLayout}> -----> how to specify "headerBar"
<Route path="/" component={Home} />
<Route path="widgets">
<Route component={SearchLayout}>
<IndexRoute component={WidgetList} />
</Route>
</Route>
</Route>
</Router>
);
在這種情況下,如何在路由指定 「headerBar」 「MainLayout」?
感謝
德里克
你使用任何一種狀態容器? (Redux,flux ...) – Shota
@shota不,我沒有使用任何容器。 – derek