Angular 使用ui-router-ng2的通配符路由?
我正在尝试将ui-router-ng2与身份验证即服务提供商Auth0一起使用。问题在于登录后,Auth0将用户重定向到如下url:Angular 使用ui-router-ng2的通配符路由?,angular,angular-ui-router,auth0,Angular,Angular Ui Router,Auth0,我正在尝试将ui-router-ng2与身份验证即服务提供商Auth0一起使用。问题在于登录后,Auth0将用户重定向到如下url: this .router .events .filter(event => event.constructor.name === 'NavigationStart') .filter(event => (/access_token|id_token|error/).test(event.url)) .subs
this
.router
.events
.filter(event => event.constructor.name === 'NavigationStart')
.filter(event => (/access_token|id_token|error/).test(event.url))
.subscribe(() => {
this.lock.resumeAuth(window.location.hash, (error, authResult) => {
if (error) return console.log(error);
localStorage.setItem('id_token', authResult.idToken);
this.router.navigate(['/']);
});
{等等..}
我尝试过更改重定向url,使其命中组件,但在auth0中这似乎是不可能的
使用ui路由器1,可以添加http截获来处理此问题,但此时angular 2中没有http截获功能
将auth0与angular 2默认路由器一起使用时,重定向的处理方式如下:
this
.router
.events
.filter(event => event.constructor.name === 'NavigationStart')
.filter(event => (/access_token|id_token|error/).test(event.url))
.subscribe(() => {
this.lock.resumeAuth(window.location.hash, (error, authResult) => {
if (error) return console.log(error);
localStorage.setItem('id_token', authResult.idToken);
this.router.navigate(['/']);
});
我浏览了ui-router-ng2文档,没有找到类似的方法
有什么想法吗?我通过在我的应用程序的根组件中执行以下操作修复了此问题:
export class AppComponent {
constructor() {
console.log("App root component created");
// Auth0 doesn't redirect properly to /#/ URLs so we have to capture token here
var regex = /(id_token=)([^&]*)/;
var vals = regex.exec(window.location.hash);
if (vals != null) {
localStorage.setItem('id_token', vals[2]);
if(localStorage.getItem('preAuthURL') != null) { window.location.href = localStorage.getItem('preAuthURL');}
}
}
}