Angular2 版本:rc3
路由器版本:3.0.0-alfa7
引导.ts:
import { provideRouter, RouterConfig } from '@angular/router';
import {AppComponent} from "./main/app.component"
import {UsersComponent, UserListComponent, UserEditComponent} from "./users/index"
export const routes: RouterConfig = [
{ path: "", redirectTo: "users", terminal: true },
{
path: "users",
component: UsersComponent,
children: [
{ path: "create", component: UserEditComponent },
{ path: "edit/:id", component: UserEditComponent },
{ path: "", component: UserListComponent }
]
}
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
当我启动应用程序时,路由器重定向到/users并且UserListComponent工作得很好。
我有两个问题:
- 从UserListComponent导航到/users/edit/:id只能通过[routerLink]指令(例如 [routerLink]="['edit', 17]")工作。但是后来我尝试使用路由器本身从UserListComponent导航(例如 router.navigate(['edit', 17]))然后什么也没有发生;
- 从它的子组件导航到/users不起作用。我试过 [routerLink]="['/users']", router.navigate(['/users'])。需要注意的是[routerLink]="['/users']"渲染到一个有效的锚标签:<'a href="http://localhost/users"></'/a>