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

Backbone.history.start not firing default route with root param #1387

Closed
ghost opened this issue Jun 7, 2012 · 4 comments
Closed

Backbone.history.start not firing default route with root param #1387

ghost opened this issue Jun 7, 2012 · 4 comments
Labels

Comments

@ghost
Copy link

ghost commented Jun 7, 2012

I have an app where the url is in the format:

    http://my.app.com/root

My routes look like this:

      routes: {
          '': 'index'
      },

However when I call Backbone history start:

     Backbone.history.start({pushState: true, root: '/root/'});

and the user navigates to http://my.app.com/root, it does not fire the '' route:

It does fire the '' route if the user adds a slash to the end of the url:

   http://my.app.com/root/

I noticed that in the start function for history, it calls this.loadUrl() without params. This ends up getting translated as a fragment of 'root' on your side and tries to get matched to my list of routes. Since I don't have a route called 'root', it doesn't match.

My question is, shouldn't you infer in loadUrl that root should point to the empty route and hit the index function like above? Otherwise I need to add 'root' as a route and point to the index function in addition to the empty route.

@cqfd
Copy link

cqfd commented Jun 14, 2012

I've reproduced this issue.

In the process, I noticed some additional odd behavior. With the following routes,

  routes: {
    '' : 'indexHandler',
    'root' : 'rootHandler'
  }

and a History.start call like this

Backbone.history.start({pushState: true, root: '/root/'});

hitting /root and /root/root both trigger the rootHandler callback. This seems like a bug.

@cqfd
Copy link

cqfd commented Jun 14, 2012

Looks like this is a duplicate bug for #1366, which @braddunbar is working on in another branch.

@ghost
Copy link
Author

ghost commented Jun 14, 2012

I don't think #1366 is the same as my issue. My problem is that i need an extra slash after root in order for it to fire the empty route.

@braddunbar
Copy link
Collaborator

This is definitely a bit different than #1366, but somewhat related. I'm wondering if perhaps we should strip the trailing slash from the root so that the comparison works either way? Navigating to "/root" instead of "/root/" seems reasonable to me. I'll take a stab at it and see what edge cases pop up.

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

No branches or pull requests

2 participants