D
D
Dmitry2017-09-29 12:34:29
Angular
Dmitry, 2017-09-29 12:34:29

How to properly configure routing in Angular2?

I do a banal routing so that you can view the list of nested categories
Top-level
/category/
categories URLs of nested categories are based on the principle
/category/f4187aa8-a415-11e7-b8ea-52540012f636
/category/f4187bd4-a415-11e7-b8ea-52540012f636
Ie . actually clicking on the category - we only change the UUID and should see nested categories
But along with changing the UUID in the URL I get an error

NavigationError
core.es5.js:1020 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'component' of null
TypeError: Cannot read property 'component' of null
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseRoutes (router.es5.js:4346)
    at router.es5.js:4308
    at Array.forEach (<anonymous>)
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseChildRoutes (router.es5.js:4307)
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseRoutes (router.es5.js:4338)
    at router.es5.js:4308
    at Array.forEach (<anonymous>)
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseChildRoutes (router.es5.js:4307)
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverse (router.es5.js:4264)
    at MapSubscriber.project (router.es5.js:4103)
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseRoutes (router.es5.js:4346)
    at router.es5.js:4308
    at Array.forEach (<anonymous>)
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseChildRoutes (router.es5.js:4307)
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseRoutes (router.es5.js:4338)
    at router.es5.js:4308
    at Array.forEach (<anonymous>)
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseChildRoutes (router.es5.js:4307)
    at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverse (router.es5.js:4264)
    at MapSubscriber.project (router.es5.js:4103)
    at resolvePromise (zone.js:824)
    at resolvePromise (zone.js:795)
    at zone.js:873
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)
    at Object.onInvokeTask (core.es5.js:3881)
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:424)
    at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (zone.js:192)
    at drainMicroTaskQueue (zone.js:602)
    at ZoneTask.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:503)
    at invokeTask (zone.js:1540)

<a [routerLink]="['/category/',row.category_uuid]">{{row.category_name}}</a>

{
    path: 'category', component: CategoryManagerComponent, canActivate: [AuthServiceComponent], 
    children: [
         { path: ':uuid', component: CategoryManagerComponent,  canActivate: [AuthServiceComponent]}
    ]}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fedor Sazonov, 2017-09-29
@Revenant20

Documentation
You can also look here.
If I correctly understood the essence of the problem, then you did not write the path correctly.
It has to be like thispath : 'category/ :uuid'

D
Dmitry, 2017-09-29
@falcon_sapsan

solved the problem in the following way.

{
    path: 'category', component: CategoryManagerComponent, canActivate: [AuthServiceComponent], children: [
    { path: ':uuid', component: CategoryManagerComponent,  canActivate: [AuthServiceComponent]}
  ]},
    {
    path: 'category-detail/:uuid', component: CategoryManagerComponent, canActivate: [AuthServiceComponent]
    },

Apparently, the uuid in child cannot be changed, this causes an error. If uuid changes at the first level, then everything is fine

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question