@Routes([
{path: '/', component: loginComponent},
{path: '/login', component: loginComponent},
{path: '/home', component: homeComponent}
])
并且在例如homeComponent中我们有这个
@Routes([
{path: '/addTemplate', component: addTemplateComponent}
}
并在/ home(我们放/ home / addTemplate)中有一些URL因为addTemplate在homeComponent中
我需要在版本RC4中知道如何应用树路由
因为我有我的组件AppComponent并且在这个AppComponent里面我有一个我希望它一直显示的菜单,在这个菜单(homeComponent)中我有另一个路由
这是我的RC4版本代码 AppRoute.ts
import { provideRouter,RouterConfig} from '@angular/router';
import {loginComponent} from "../login/login.component";
import {homeComponent} from "../home/home.component";
import {HomeRoutes} from "./RouteHome";
export const routes : RouterConfig = [
...HomeRoutes,
{path: '', component: loginComponent},
{path: 'login', component: loginComponent},
{path: 'home', component: homeComponent}
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
export const HomeRoutes : RouterConfig = [
{path: 'addTemplate', component: addTemplateComponent}];
当我致电this._router.navigate(['addTemplate']);
时
我得到addTemplateComponent没有菜单(homeComponent)
所以我需要像在angular2 rc2中那样做someThing保持标题,我有我的菜单感谢提前
答案 0 :(得分:2)
这主要取决于你打电话的地方
this._router.navigate(['addTemplate']);
也许你想要
this._router.navigate(['/addTemplate']);
或
this._router.navigate(['addTemplate'], {relativeTo: route});
或
this._router.navigate(['../addTemplate'], {relativeTo: route});