Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

Get base url in angular outside of component

We're using the Msal library to handle authentication and it takes a redirect URL, which has to be the same one the user is accessing to work properly.

The config for that is in the app.module.ts, before defining the NgModules, so I can't get the router in a constructor. Is there a way there to get the base domain the user is accessing ?

I have been using an environment variable to store this for now but it's very limiting, I'd like it to work for multiple domains transparently. Since the redirect url are stored and verified by microsoft anyway during authentication, passing whatever the user is accessing from the frontend should be fine.

Thank you

question from:https://stackoverflow.com/questions/65883537/get-base-url-in-angular-outside-of-component

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Hadn't realized this was an optional config :

redirectUrl: Location to redirect, can be a relative of absolute url. (optional, default: window.location.href);

The default is actually what I'm looking for, so nevermind ! Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...