0

Thats my route config:

export const SchoolyearsRoutes: RouterConfig = [
  { path:'', terminal:true, redirectTo: '/schoolyears'},
  { path: 'schoolyears',  component: SchoolyearsListComponent },
  { path: 'schoolyears/edit/:id', component: SchoolyearsEditComponent },
  { path: 'schoolyears/create', component: SchoolyearsCreateComponent }

but I want to have it as:

export const SchoolyearsRoutes: RouterConfig = [
  { path:'', terminal:true, redirectTo: '/schoolyears'},
  { path: 'schoolyears',  component: SchoolyearsListComponent },
  { path: 'edit/:id', component: SchoolyearsEditComponent },
  { path: 'create', component: SchoolyearsCreateComponent }

I want that edit/create route prepend the base url 'schoolyears' implicitly during runtime.

How can I achieve this without restructure my components?

UPDATE

Although I use TypeScript I get a runtime exception which should actually happen at compile time:

browser_adapter.ts:84EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'annotations' of undefined
Elisabeth
  • 20,496
  • 52
  • 200
  • 321

1 Answers1

2
export const SchoolyearsRoutes: RouterConfig = [
  { path:'', terminal:true, redirectTo: '/schoolyears'},
  { path: 'schoolyears', component: SchoolyearsRootComponent, children: [
     { path: '',  component: SchoolyearsListComponent },
     { path: 'edit/:id', component: SchoolyearsEditComponent },
     { path: 'create', component: SchoolyearsCreateComponent }
  ] }
]

Isn't it something that resolves your case?

Wojciech Kwiatek
  • 6,634
  • 2
  • 16
  • 26
  • Actually yes. I thought something "./childpath" would work, but children is new router3 feature... I get a runtime exception with your code - though it compiles without problem - I updated my question with the error message I get. Seems its that problem: http://stackoverflow.com/questions/38065325/angular-2-child-routing-v3-cannot-read-property-annotations-of-undefined – Elisabeth Jun 28 '16 at 17:48
  • I added `SchoolyearsRootComponent` to the answer. Path `schoolyears` was lacking a `component`. In your case it would probably include only a `` – Wojciech Kwiatek Jun 28 '16 at 18:20
  • I also found out that I need another WrapperComponent. then I get the exception: cannot find primary outlet. I thought these Wrapper/Home components were gone with router3. So the SchoolyearsRootComponent just needs a template: `` is that correct? – Elisabeth Jun 28 '16 at 18:27