React-Router: PlainRoute对象

完整代码:


export const createRoutes = (store) => ({
  path        : '/',
  component   : CoreLayout,
  indexRoute  : {onEnter: (nextState, replace) => replace('/cat')},  
  childRoutes : [
    CatRoute(store),
    DogRoute(store)
  ]
})

export default createRoutes

解释是如下:
path作为路径名称,由于这里是根route,所以只用'/'作为名字。
component:这个router要渲染的component。
indexRoute稍后解释
childRoutes: 相当于正常下的

在PlainRoute中,indexRoute代表了path对应的默认页面,通常他的值只是一个简单的component,例如:

 indexRoute  : Home,  

在这里“Home”是被引入的一个component。

然而在某些时候我们希望当用户访问根页面的时候自动将他们redirect到其他的页面,例如用户访问"www.pet.com"时,你希望直接让他们看到"www.pet.com/cat"这个页面,这时你需要对indexRoute的值做出如下修改:

 indexRoute  : {onEnter: (nextState, replace) => replace('/cat')},  

你可能感兴趣的:(React-Router: PlainRoute对象)