【问题标题】:Specify default route in React Router using the 1.0 API使用 1.0 API 在 React Router 中指定默认路由
【发布时间】:2015-07-11 20:13:14
【问题描述】:

使用 1.0 API 将路由声明为对象时,如何指定默认路由?

const routes = {
  path: '/',
  component: App,
  childRoutes: [
    { name: 'welcome', component: Welcome },
    // Default route here
  ]
};

【问题讨论】:

    标签: javascript react-router


    【解决方案1】:

    我也有同样的疑问,我已经解决了这个问题,但不确定这是否正确,在您的“应用程序”组件中按照以下方式操作

    let App = React.createClass({
        componentDisMount: function() {
            this.transitionTo('deafaultComponent'); 
            //default compoenent you say its your home page. 
            //so when ever somebody used yourwebsite.com/ 
            //it will redirect to yourwebsite.com/defaultComponent
        },
        render: function() {
             {this.props.children}
        }
     );
    

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 2015-09-30
      • 1970-01-01
      • 2016-01-14
      • 1970-01-01
      • 2017-03-07
      • 1970-01-01
      • 2016-10-22
      • 2022-01-23
      相关资源
      最近更新 更多