0

I have a backbone application residing at say, http://foo.com. My application behaves different for different region, so say if I navigated to http://foo.com/TX different set of information is loaded, while if I navigate to http://foo.com/OK another set of information is loaded. These necessarily do not form part of the backbone route and are part of the url itself.

I have also modified my backbone route to ignore this second parameter in the url while considering routes in my router initialize function,

routes = [
    [/\w+/,             'default',      this.default],
    [/\w+\/login/,      'login',        this.login]
];
_.each(routes, function(route) {
    router.route.apply(router,route);
});

But when I do app.navigate("login", true), it changes my URL to http://foo.com/home. What I expect to see is http://foo.com/TX/home, so that it retains the region information. How can I achieve that?

etrast81
  • 280
  • 1
  • 4
  • 16
  • Were you ever able to solve this problem? – Michael.Lumley Apr 29 '15 at 10:23
  • Thanks for nudging me and sorry about the delay. Actually I solved it instead using URL Rewrites. If I set up a rewrite rule to by pass the second bit of URL, then without the regex based route itself the routing works. This also ensures that the URL still retains the location information. – etrast81 Apr 30 '15 at 10:51

1 Answers1

0

Assuming your app is located at a given location, your router is going to go back to that location, without adding on the extra region code. One option would be to extend your router model and override backbone's navigate function (documentation) to incorporate the region codes, but that could be dangerous and beyond the scope of what you'd like to take on yourself.

Another option is to call the path on your router without updating the URL (documentation). This would run your code and update the page, but would not reset the URL as you desire. with this option, you would want to call the router with the option

router.route.apply("login", {trigger: true, replace: false})
Michael.Lumley
  • 2,345
  • 2
  • 31
  • 53