本文介绍了角2 - 如何使用导航到另一条路线this.router.parent.navigate('/约“)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2角 - 如何使用导航到另一条路线this.router.parent.navigate('/约')

Angular 2 - How to navigate to another route using this.router.parent.navigate('/about').

它似乎没有工作。
我试图location.go(/约);因为没有工作。

It doesnt seem to work.I tried location.go("/about"); as that didnt work.

基本上一旦用户登录,我想将它们重​​定向到另一页。

basically once a user has logged in I want to redirect them to another page.

下面是我的code以下:

Here is my code below:

 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');

       });
   }
 }

感谢你在前进!

推荐答案

我认为你应该使用

this.router.parent.navigate(['/About']);

这篇关于角2 - 如何使用导航到另一条路线this.router.parent.navigate('/约“)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 17:06