angular url parameter fails to fetch without url ending in #
up vote
0
down vote
favorite
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 /#/
angular angular-activatedroute
add a comment |
up vote
0
down vote
favorite
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 /#/
angular angular-activatedroute
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 yourRouterModule.forRoot(routes)
use extra options likeRouterModule.forRoot(routes, useHash: false )
– Suryan
Nov 9 at 3:05
Looks like you are usingPathLocationStrategy
and expecting it work asHashLocationStrategy
. Check yourAppModule
whatLocationStrategy
you have used.
– Sunil Singh
Nov 9 at 3:53
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 /#/
angular angular-activatedroute
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 /#/
angular angular-activatedroute
angular angular-activatedroute
edited Nov 9 at 3:51
Suryan
50339
50339
asked Nov 9 at 2:43
Vik
1,91584088
1,91584088
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 yourRouterModule.forRoot(routes)
use extra options likeRouterModule.forRoot(routes, useHash: false )
– Suryan
Nov 9 at 3:05
Looks like you are usingPathLocationStrategy
and expecting it work asHashLocationStrategy
. Check yourAppModule
whatLocationStrategy
you have used.
– Sunil Singh
Nov 9 at 3:53
add a comment |
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 yourRouterModule.forRoot(routes)
use extra options likeRouterModule.forRoot(routes, useHash: false )
– Suryan
Nov 9 at 3:05
Looks like you are usingPathLocationStrategy
and expecting it work asHashLocationStrategy
. Check yourAppModule
whatLocationStrategy
you have used.
– Sunil Singh
Nov 9 at 3:53
1
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 9 at 3:05
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 9 at 3:05
Looks like you are using
PathLocationStrategy
and expecting it work as HashLocationStrategy
. Check your AppModule
what LocationStrategy
you have used.– Sunil Singh
Nov 9 at 3:53
Looks like you are using
PathLocationStrategy
and expecting it work as HashLocationStrategy
. Check your AppModule
what LocationStrategy
you have used.– Sunil Singh
Nov 9 at 3:53
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219109%2fangular-url-parameter-fails-to-fetch-without-url-ending-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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 yourRouterModule.forRoot(routes)
use extra options likeRouterModule.forRoot(routes, useHash: false )
– Suryan
Nov 9 at 3:05
Looks like you are using
PathLocationStrategy
and expecting it work asHashLocationStrategy
. Check yourAppModule
whatLocationStrategy
you have used.– Sunil Singh
Nov 9 at 3:53