Skip to content

Redirecting to state with no URL in transition hook ignores location=false #3317

@smhc

Description

@smhc

I have a login state with no URL specified. The idea is when navigating to a given state they will be redirected to the login state if they aren't logged in. The URL shouldn't be updated in this case - it should reflect the intended state. If they login, the state is synced with the url via $urlRouter.sync().

However what is happening is:

redirect to login
transition login Object {
    location: "replace", 
    relative: null, 
    inherit: true, 
    notify: false, 
    current:
    custom:
    inherit: true
    location: "replace"
    notify: false
    redirectedFrom: Transition
    relative: null
    reload: false
    reloadState: undefined
    source: "redirect"
passing through 
transition home Object {
    location: true,
    relative: null,
    inherit: true,
    notify: true,
    current: 
    custom: 
    inherit: true
    location: true
    notify: true
    relative: null
    reload: false
    reloadState: undefined
    source: "url"
redirect to login
transition login Object {
    location: "replace", 
    relative: null,
    inherit: true,
    notify: false,
    current:
    custom:
    inherit: true
    location: "replace"
    notify: false
    redirectedFrom: Transition
    relative: null
    reload: false
    reloadState: undefined
    source: "redirect"
passing through 

The redirect is using code similar to:

return $state.target('login', [], { custom: { xx: 'asdf'} , notify: false, location: false });

But location is being set to 'replace'. Because the login state doesn't have a URL, it is being set to '/', which modifies the URL, losing the intended url and causing extra state redirects (intended -> login -> / -> login)

(ui router v1.0.0-rc.1, angular 1.6.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions