我有一个有角度的应用程序,并试图获取url参数。路由器配置如下所示
export const appRoutes: Routes = [
{ path: '', component: SharepointMainComponent },
{ path: 'userProfile' ,component: UserDataComponent, canActivate : [MsalGuard]},
{ path: '**', component: ErrorComponent }
];
和SharepointMainComponent构造函数如下所示
constructor(private activatedRoute: ActivatedRoute,) {
//get optyNumber from url
this.activatedRoute.queryParams.subscribe(params => {
let optyNumber = params['optyNumber'];
console.log("optyNumber:" + optyNumber);
});
}
如果我输入网址 http://myserver.com?optyNumber=1234
然后我得到未定义的值。但是,如果我输入 http://myserver.com/#/?optyNumber=1234
然后它会正确打印值。我需要做什么才能使其与/#/
一起使用