Reputation: 2847
I am trying to add a query parameter as the first parameter in backbonejs route but no luck.
Below is my router config.
TabsRouter = Backbone.Router.extend({
routes: {
"tab/:tabname": "goToTab",
"*default": "defaultTab"
},
goToTab: function(tabName) {
view.renderTab(tabName);
},
defaultTab: function() {
view.renderTab('markets');
}
});
tabsRouter = new TabsRouter();
The above code works fine and i can access the routes like baseurl/#tab/personal but i want something baseurl/#personal, I don't want to start with tab. I have tried ":tabname" route but its not working.
Any help would be appreciated.
Upvotes: 0
Views: 72
Reputation: 4248
One of best way that you can solve your trouble is using different paths for each tab.
Following your code, it would be:
TabsRouter = Backbone.Router.extend({
routes: {
"tab/first-tab": "firstTabView",
"tab/second-tab": "secondTabView",
"tab/third-tab": "thirdTabView",
"*default": "defaultTab"
},
firstTabView: function() {
view.renderFirstTab();
},
secondTabView: function() {
view.renderSecondTab();
},
thirdTabView: function() {
view.renderThirdTab();
},
defaultTab: function() {
view.renderDefault();
}
});
tabsRouter = new TabsRouter();
Hope it helps you.
Upvotes: 0