I am trying to use a route Router.navigate. I followed the instructions for the letter, but when I go through the API, it reloads the root page.
In mine RootComponentI try to use
this._router.navigate (['ABC', 'Page1']); which should redirect me to application / abc / xyz
But if I directly visit application/abc/xyzthrough my browser, it works without problems
app.component.ts
import {Component} from "angular2/core";
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from "angular2/router";
import {RootComponent} from "./components/root.component";
import {Page1Component} from "./components/page1.component";
@Component({
selector: 'app',
template: '<router-outlet></router-outlet>',
directives: [ROUTER_DIRECTIVES],
providers: [
ROUTER_PROVIDERS
]
})
@RouteConfig([
{
path: '',
name: 'Root',
component: RootComponent,
useAsDefault: true
},
{
path: '/abc/...',
name: 'ABC',
component: ABCComponent
}
])
export class AppComponent {
}
Abccomponent
@Component({
selector: 'abc',
template: '<router-outlet></router-outlet>',
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{
path: '/xyz',
name: 'Page1',
component: Page1Component
}
])
export class ABCComponent{
constructor(private _router:Router){
}
}
Page1Component
import {Component} from "angular2/core";
import {Router} from "angular2/router";
@Component({
selector: 'page1',
template: '<h1>Page1</h1>'
})
export class Page1Component{
constructor(private _router:Router){
}
}
What am I doing wrong?
EDIT
To explain this even simpler terms
Application (2 routes at root level)
| |
Default ("/") - Root Component /abc/ ABC Component
|
/abc/xyz Page1 Component
What I'm trying to do is go to Page1 from the root component.
Decision
After the reverse enineering from S.alem plunkr, here is the solution
http://plnkr.co/edit/F1p6aQNJ7lREHCiVnKEP?p=preview