react.js如何设置DefaultRouter?

时间:2015-10-12 12:53:06

标签: javascript reactjs react-router

我正在尝试设置路由层次结构。现在它看起来像:

const routes = {
  path: '/',
  component: 'div',
  indexRoute: MainApp,
  childRoutes: [
    { path: '/', name: 'dashboard', component: MainApp},
    { path: 'quiz', name: 'quiz', component: QuizApp}
  ]
};

如果点击href="#quiz"的链接,我可以看到QuizApp。但是jus加载主页我只能看到我在index.html文件中写的内容。如何正确设置DefaultRouter?

以下是依赖项:

"react": "^0.14.0-beta3",
"react-dom": "^0.14.0-beta3",
"react-redux": "^1.0.1",
"react-router": "^1.0.0-rc3",
"redux": "^1.0.1",

1 个答案:

答案 0 :(得分:0)

我已经发现,我不能只设置组件的名称,我必须设置一个至少具有'component'属性的对象:

const routes = {
  path: '/',
  component: 'div',
  indexRoute: {component: MainApp},
  childRoutes: [
    { path: '/', name: 'dashboard', component: MainApp},
    { path: 'quiz', name: 'quiz', component: QuizApp}
  ]
};