使用1.0 API在React Router中指定默认路由

时间:2015-07-11 20:13:15

标签: javascript react-router

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

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

1 个答案:

答案 0 :(得分:0)

我也有同样的疑问,我已经解决了这个问题,但不确定这是否正确,在你的“App”组件中如下所示

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}
    }
 );