angular - Fetch #access_token from URL -
my landing url after sso login is:
now, how can fetch #access_token
value url?
use function provided below token value
//get token value url //you can use window.location.href or pass value please let token: string = getparameterbyname("access_token", location.href); public getparameterbyname(name: string, url: string): string { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); let regex = new regexp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeuricomponent(results[2].replace(/\+/g, " ")); }
if want value in routing event
in component imports router
this.router.events .filter(event => event instanceof navigationend) .map(() => this.activatedroute) .map(route => { while (route.firstchild) route = route.firstchild; return route; }).filter(route => route.outlet === 'primary') .mergemap(route => route.data) .subscribe((event) => { //use code here value } );
Comments
Post a Comment