auth0路由器不会触发导航

时间:2017-04-07 20:04:22

标签: javascript angular auth0

我在Angular 2中使用Auth0。我有以下登录代码,在验证后不会进入主页。

根据我的理解,auth0不会进行重定向。它发送经过身份验证的事件,它应该在localstorage中创建一个项目,然后导航到主页。

@Injectable()
export class AuthService {

    lock = new Auth0Lock(this.config.clientID, this.config.domain, {
        auth: {

            responseType: 'token',
        }
    });

    constructor(private http: Http, private config: AppConfig, private router: Router) { 
        // Add callback for lock `authenticated` event
        this.lock.on('authenticated', (authResult) => {
            localStorage.setItem('id_token', authResult.idToken);
            console.log(localStorage);
            this.router.navigate(['home']);
        });
    }

1 个答案:

答案 0 :(得分:1)

您可以尝试 location.replace(&#39; / home&#39;) location.replace(&#39; http://localhost:4200/home&#39;)< /强>