eri*_*icn 4 reactjs react-router
我尝试过以下内容并且无法正常工作:
const routeConfig = [
{
// path: '/',
component: MyApp,
indexRoute: {component: Homepage},
childRoutes: routes
}
];
React.render(<Router history={history} routes={routeConfig} />, document.getElementById('content'));
Run Code Online (Sandbox Code Playgroud)
"Homepage"组件完全被忽略!
我正在使用react-router 1.0.0并反应0.13.3
首先,要做的最好的事情是升级到1.0最终版(没有重大变化 - 只是错误修复)
请参阅下面的示例,了解如何使用普通路由IndexRoute:
import React from 'react'
import { render } from 'react-dom';
import createBrowserHistory from 'history/lib/createBrowserHistory'
import { Router } from 'react-router'
const Home = () =>
<h3>Home</h3>
const App = (props) =>
<div>
<h1>App</h1>
<Navigation />
{props.children}
</div>
const routes = [
{
path: '/',
component: App,
indexRoute: {
component: Home
}
}
]
const Root = () =>
<Router history={createBrowserHistory()} routes={routes} />
render(<Root />, document.getElementById('root'));
Run Code Online (Sandbox Code Playgroud)
编辑:我在这里为你创建了一个例子.克隆repo时,导航到plain-routesexample和npm install && npm start.
| 归档时间: |
|
| 查看次数: |
2713 次 |
| 最近记录: |