javascript - React-router引入IndexRoute报错
本文介绍了javascript - React-router引入IndexRoute报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
import React from 'react'
import { Router, Route, IndexRoute, hashHistory } from 'react-router'
import Frame from '../layouts/Frame'
import Home from '../views/Home'
import Detail from '../views/Detail'
const routes = (
<Router history={hashHistory}>
<Route path="/" component={Frame} />
<IndexRoute component={Home} />
<Route path="/detail:id" component={Detail} />
</Router>
)
export default routes
Warning: [react-router] An <IndexRoute> does not make sense at the root of your route config
IndexRoute组件里的Home组件是正常的,单独拿出来也能显示,实在不清楚报错的原因
解决方案
例子上是这个样子的,你是不是写的结构有问题?
<Router>
<Route path="/" component={App}>
<IndexRoute component={Home}/>
<Route path="accounts" component={Accounts}/>
<Route path="statements" component={Statements}/>
</Route>
</Router>
这篇关于javascript - React-router引入IndexRoute报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文