Skip to content

Unmatched route with root option and popstate event #82

Closed
@sndrgb

Description

@sndrgb

Hi, this was my scenario:

  1. route initialized with history option true and root option set to /en like this:
router = new Router({
    history: true,
    root: utils.lang
});
  1. navigating from homepage ( /en ) to contact ( /en/contact )

  2. clicking back button for come back to homepage ( /en ) matches default '404' route ( * )

after some tries and investigations i think i've found a little bug in /src/history/html5.js p.start method where this.listener function loses its context. i resolve binding the function to this

 this.listener = function (e) {
    var url = decodeURI(location.pathname + location.search)
    if (this.root) {
      url = url.replace(this.rootRE, '')
    }
    self.onChange(url, e && e.state, location.hash)
  }.bind(this);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions