【问题标题】:react.js how to set up DefaultRouter?react.js如何设置DefaultRouter?
【发布时间】:2023-03-30 01:31:02
【问题描述】:

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

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

如果我单击带有href="#quiz" 的链接,我可以看到QuizApp。但是只是加载主页我只能看到我在 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",

【问题讨论】:

    标签: javascript reactjs react-router


    【解决方案1】:

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

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

    【讨论】:

    • React Router 1.0 不再使用命名路由,请参阅Upgrade Guide
    猜你喜欢
    • 2019-05-22
    • 1970-01-01
    • 2017-08-20
    • 2015-08-10
    • 1970-01-01
    • 2019-09-26
    • 2015-04-13
    • 2015-08-21
    • 1970-01-01
    相关资源
    最近更新 更多