简体   繁体   中英

Redirect from back-end to angular2 component

Let's say I have web api controller. After executing some logic I want to redirect to provided redirectUrl passing some values. For example:

public async Task<IActionResult> Callback()
{
    var redirectUrl = "some_url#parameter1=value1";
    return Redirect(redirectUrl);
}

For client side application I am using Angular2 and what I am trying to achieve is to redirect to my component based on redirectUrl and execute specific method in my angular2 component. What is the best approach to do it?

We did something similar to this on our project. But instead we let the client handle the redirect logic & URL building. We only passed back in the response data to build the url.

http.post("someUrl").subscribe((response) => {
  // build URL and redirect based on response
});

Another approach we tried was to redirect to a static URL. This was messy with Url Building as our .net side didn't have good support for matrix urls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM