Skip to content

Add replaceState support #84

Open
Open
@ralphsmith80

Description

I'm using a setTimeout in .to so the path will resolve before forwarding to another route. This maybe the reason the add delay() issue was filed since that's what I started investigating before I realized the behavior I want to achieve is supported by IE10+ browsers with history.replaceState.

Example:

Path.map('/app').to(function() {
  // timeout is set so that the `history.pushState` happens before we navigate to the route we want
  // to redirect to https://github.com/mtrpcic/pathjs/blob/master/path.js#L21
  setTimeout(function() {
    var id = '1234';
    Path.history.pushState({}, null, '/app/'+id);
  }, 0);
});
Path.map('/app/:id').to(function() {
  // do stuff with a view that require an id, i.e. this.params.id
});

Using the setTimeout is functionally correct but if I use the back button I would go back to /app which would just forward me back to /app/1234. If I use replaceState then I replace history with the correct url so the back button functions how a user would expect it to.

Basically a redirect that is opaque to the user so we shouldn't keep that in history. i.e. use history.replaceState.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions