0

我有一个角度应用程序并试图获取 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

然后它打印的值就好了。我需要做什么才能使用 /#/

4

0 回答 0