Angular 2 - 如何使用this.router.parent.navigate('/ about')导航到另一条路线。Angular 2 - 如何使用this.router.parent.navigate('/ about')导航到另一条路线
它似乎没有工作。 我试过location.go(“/ about”);因为那没用。
基本上一旦用户已经登录,我想将它们重定向到另一页。
这里是我下面的代码:
import {Component} from 'angular2/angular2';
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/angular2';
import {Router} from 'angular2/router';
import {AuthService} from '../../authService';
//Model
class User {
constructor(public email: string, public password: string) {}
}
@Component({
templateUrl:'src/app/components/todo/todo.html',
directives: [CORE_DIRECTIVES, FORM_DIRECTIVES]
})
export class Todo {
model = new User('[email protected]', 'Password');
authService:AuthService;
router: Router;
constructor(_router: Router, _authService: AuthService){
this.authService = _authService;
this.router = _router;
}
onLogin =() => {
this.authService.logUserIn(this.model).then((success) => {
//This is where its broke - below:
this.router.parent.navigate('/about');
});
}
}
预先感谢您!
另外,我设置我的应用程序的路由配置。TS文件像这样: @RouteConfig([ \t {路径: '/',redirectTo: '/家'}, \t {路径: '/家',组分:藤,如: '首页'}, \t {path:'/ about',component:About,as:'About'} ]) – AngularM
您应该删除路径中的'/'因为它不是必需的 – mast3rd3mon