Search code examples
angularjsangular-ui-routerangular-http-interceptors

Pass route via query string in ui-router


Using angular interceptors and route-ui I am capturing a 401 Unauthorized request and redirecting to a login url.

I want to send the state the user was previously in on the query string to redirect after successful login but I can't find the actual url with parameters included in the $state service.

This is what i have but $state.current.url does not include the parameters of the state.

$state.go('home.login', {next: $state.current.url});
//$state.current.url = /user/{id}
//$state.params      = {id:5}

I would like the url to be something like:

http://example.com/login?next=/user/5

And after a successful login the user would be redirected to http://example.com/user/5

Is there any way i can get the /user/5 url from the $state service?


Solution

  • Using the $locationservice:

    $location.path()
    

    check more here