Search code examples
backbone.jsroutestrailing-slash

Avoid traliing slash for default routes in Backbone.js


I'm looking for something to accomplish in Backbone. Here is the explanation.

I have backbone routes like

{
    '': 'defaultRoute',
    'test': 'test',
    'testing': 'testing'
}

Assuming my root url is '/routes'

Now when I say 'router.navigate('test', {trigger: true});' url changes to /routes/test.

Similar way when I call 'router.navigate('testing', {trigger: true});' url changes to /routes/testing.

But when I call 'router.navigate('', {trigger: true});' url changes to /routes/.

You know i didn't expect that / at the end. I never passed that. It should have been back to root url i.e. '/routes'.

Adding / at the end makes lot of difference/meaning. Checkout 'http://googlewebmastercentral.blogspot.in/2010/04/to-slash-or-not-to-slash.html'

Any fix for that (i.e. not having / at the end for default route)?


Solution

  • Update:-

    This has been already fixed in Backbone's latest version. I asked a question on there forum and found the answer. I'm adding it here as an answer if it helps anyone who is looking for the same thing.

    https://github.com/jashkenas/backbone/issues/2871