1

I'm missing something here. My problem is very simple I think. mysite.com/app and mysite.com/transaction both load a different html page but they load the same router.

For each case I need my router to be written in order than mysite.com/app/#/someparams triggers 'app' function mysite.com/transaction/#/someparams triggers 'transaction' function. (With or without # I don't care but this is the way it works for me =/ )

If I write :

routes: {
    'app':'app',
    'app/:params':'app',
    'transaction':'transaction',
    'transaction/:params': 'transaction'
}

Backbone.history.start({
    pushState: true 
});

Then mysite.com/app/#/params or mysite.com/transaction/#/params won't trigger the wanted functions.

If I write this:

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

then parameters will be ok for /app but not for /transaction. What to do ? I'm pretty sure I'm missing something simple but I'm kinda confused right now ..

Thanks for your help

François Richard
  • 6,817
  • 10
  • 43
  • 78

1 Answers1

1

Your route is only expecting a single parameter in both the routes that you have defined.

mysite.com/app/#/params matches app/:params The # is being passed in as a parameter here.

Also the hash should be preceding the route map.

mysite.com#app/params This would match the route expected by backbone as per your map.

You could just use 2 routes using the optional feature.

routes: {
    'app(/:params)':'app',
    'transaction(/:params)':'transaction'
}
Sushanth --
  • 55,259
  • 9
  • 66
  • 105
  • true but then the wrong html is loaded. mysite.com => landing , mysite.com/app => app , mysite.com/transaction => transaction ... Any idea how to roganize this ? – François Richard Nov 23 '15 at 18:58
  • you mean app(/*) ? otherwise regexp error is triggered, however when I use app(/*) my paramters are not passed ... app:fucntion(params) { ... gives me null params when I try app/#/wtv – François Richard Nov 23 '15 at 19:07
  • it seems I have the same issue than that : https://github.com/jashkenas/backbone/issues/810 , so basically I would have to point /app and /transaction with the same root, something like /tool/#/app & tool/#/transaction what do you think ? – François Richard Nov 23 '15 at 19:25