Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double / in History.navigate fallback #1207

Closed
gustaff-weldon opened this issue Apr 10, 2012 · 3 comments
Closed

Double / in History.navigate fallback #1207

gustaff-weldon opened this issue Apr 10, 2012 · 3 comments

Comments

@gustaff-weldon
Copy link

Assume that Backbone is started with the following configuration:
Backbone.history.start({ pushState: true, hashChange : false})
Also, History options.root is left at default value which is /

Invoking navigate("/index") on router in browser not supporting pushState causes "Page Not Found" error. Browser address bar shows "http://index" without the host.

This is caused by double / passed to window.location.assign when this.options.root and fragment are concatenated.

Possible fix is to use frag which is already a fragment with leading / stripped.

So instead of

  // If you've told us that you explicitly don't want fallback hashchange-
  // based history, then `navigate` becomes a page refresh.
  } else {
    window.location.assign(this.options.root + fragment);
  }

Use

  // If you've told us that you explicitly don't want fallback hashchange-
  // based history, then `navigate` becomes a page refresh.
  } else {
    window.location.assign(this.options.root + frag);
  }
@braddunbar
Copy link
Collaborator

From the docs for Router:

Note that you'll want to avoid using a leading slash in your route definitions:

Is there any reason not to just use navigate('index') instead of navigate('/index')?

@braddunbar
Copy link
Collaborator

Also, I believe this is a duplicate of #1206. Would you mind directing further discussion there? Thanks!

@gustaff-weldon
Copy link
Author

Thanks for the clarification, I was mislead by the frag which gets / stripping treatment and is used for pushState and hashChange cases . When do you plan next stable release with #1205 fix included?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants