typescript - Route with children cannot be match, when navigating to it -


good day. can't understand how new routes children work in angular 2 rc 4. want route testcomponent, have child, error "cannot match route 'test'" appear. routing way: this.guide.navigate(['test']);. how declare routes:

const routes: routerconfig = [     {         path: '',         component: logincomponent     },     {         path: 'pin',               component: pincomponent,    },     {        path: 'test',        component: testcomponent,        children: [         {             path: '/:page',             component: foodcomponent         }       ]     }   ]  export const mainrouterproviders = [   providerouter(routes) ]; 

i cannot use page default in test (like "path: '/'") because children tabs , list loading in testcomponent's constructor.

there few things

  • add pathmatch: 'full', first route, otherwise example /ping search child route ping in logincomponent

  • add default route test redirects default id or dummy component. angular doesn't if component has <router-outlet> no route add component.

const routes: routerconfig = [     {         path: '',         pathmatch: 'full',         component: logincomponent     },     {         path: 'pin',               component: pincomponent,    },     {        path: 'test',        component: testcomponent,        children: [         {             path: '',             pathmatch: 'full',             redirectto: 'mydefaultid'             // or              // component: dummycomponent         },         {             path: '/:page',             component: foodcomponent         }       ]     }   ]; 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -