当我在@ azure / msal-angular 0.1.1中使用angular 5.2.11时,在完成登录过程并返回到我的路由之一后,收到以下错误消息。
错误错误:未捕获(承诺):错误:无法匹配任何路由。网址段:“ id_token”
有几条帖子说要添加<base href="/">
,但我仍然没有帮助。
以下是我的package.json。整个项目是通过vs2017(15.8.2)-> angular模板创建的。
{
"name": "WebApplication1",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --extract-css",
"build": "ng build --extract-css",
"build:ssr": "npm run build -- --app=ssr --output-hashing=media",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.2.11",
"@angular/common": "^5.2.11",
"@angular/compiler": "^5.2.11",
"@angular/core": "^5.2.11",
"@angular/forms": "^5.2.11",
"@angular/http": "^5.2.11",
"@angular/platform-browser": "^5.2.11",
"@angular/platform-browser-dynamic": "^5.2.11",
"@angular/platform-server": "^5.2.11",
"@angular/router": "^5.2.11",
"@azure/msal-angular": "^0.1.1",
"@nguniversal/module-map-ngfactory-loader": "^5.0.0",
"aspnet-prerendering": "^3.0.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/cli": "^1.7.4",
"@angular/compiler-cli": "^5.2.11",
"@angular/language-service": "^5.2.11",
"@types/jasmine": "^2.8.8",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.117",
"codelyzer": "^4.4.4",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^2.0.5",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.4.3",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
},
"optionalDependencies": {
"node-sass": "^4.9.0"
}
}
答案 0 :(得分:0)
我通过在app.routing.ts文件中放置以下代码来解决此问题
{
path: 'id_token',
redirectTo: 'path-you-want-to-redirect-to',
},
此外,如果您想使用其他解决方法,则可以在app.component.ts文件中使用以下代码
ngOnInit() {
this.router.events.filter((event: any) => event instanceof NavigationStart)
.subscribe((data: NavigationStart) => {
if (data.url === '/id_token') {
this.hash = window.location.hash;
this.router.navigate(['path-you-want-to-navigate-to']);
}
});
}
我建议将路由添加到routing.ts文件中。