我是angular 2的新手,我使用的是angular 2.0.0版本的ng2-admin模板。我想从组件中路由我的页面,比如如果用户成功登录,然后路由到仪表板page.Currently我正在使用"route.navigate(' dashboard ')“,但在调用函数后,它给我错误,如未定义的路由。组件端代码如下:

我的module.ts文件是

我的登录路由组件是:

主路由组件为:

请帮帮我,谢谢
发布于 2016-11-10 19:05:20
您必须import { RouterModule, Routes } from '@angular/router';,然后必须在app.ts或main.ts中声明如下所示的路由
const routes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: DashboardComponent },
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})然后,您可以在相应的组件中使用routes,如下所示:
this.router.navigate(['/dashboard']);添加新的function
gotoDashBoard() {
console.log("coming");
console.log(this);
this.router.navigate(['/dashboard']);
}然后在你的response => {this.gotoCrises()}中使用call。
https://stackoverflow.com/questions/40526000
复制相似问题