0

I have an angular app and trying to get url parameters. The router config is like below

export const appRoutes: Routes = [
  { path: '', component: SharepointMainComponent  },
  { path: 'userProfile' ,component: UserDataComponent, canActivate : [MsalGuard]},
  { path: '**', component: ErrorComponent }
];

and the SharepointMainComponent constructor is like below

constructor(private activatedRoute: ActivatedRoute,) {
    //get optyNumber from url
    this.activatedRoute.queryParams.subscribe(params => {
      let optyNumber = params['optyNumber'];
      console.log("optyNumber:" + optyNumber); 
    });
}

If i type the url http://myserver.com?optyNumber=1234

then i get the value undefined. However, if i type http://myserver.com/#/?optyNumber=1234

then it prints the value just fine. What do i need to do to make it work with using the /#/

Suryan
  • 701
  • 7
  • 17
Vik
  • 8,721
  • 27
  • 83
  • 168
  • 1
    With `#` or without `#`, as your question said you get the value just fine with `#` and get undefined without `#`. Assume you want the value without `#` then in your `RouterModule.forRoot(routes)` use extra options like `RouterModule.forRoot(routes, { useHash: false })` – Suryan Nov 09 '18 at 03:05
  • Looks like you are using `PathLocationStrategy` and expecting it work as `HashLocationStrategy`. Check your `AppModule` what `LocationStrategy` you have used. – Sunil Singh Nov 09 '18 at 03:53

0 Answers0