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

onRoute parameter incorrect if multiple routes use same action #2992

Closed
berniezhao opened this issue Apr 26, 2016 · 1 comment
Closed

onRoute parameter incorrect if multiple routes use same action #2992

berniezhao opened this issue Apr 26, 2016 · 1 comment

Comments

@berniezhao
Copy link

Let's say we have multiple routes pointing to the same controller action

...
 appRoutes: {
        'home': 'displayHome',
        'home/:menu/:id': 'displaySecondLevel',
        'home/aboutus/contactus/email': 'displaySecondLevel'
    },

onRoute: function(name, path, params) {
    console.log.apply(console, arguments);
}

If I visit http://yourdomain.com/#home/product/features, the correct route was picked and onRoute function will be triggered. However the path is actually wrong. It will be home/aboutus/contactus/email instead of home/:menu/:id.

I think Marionette uses the below undercore function to find the path
var routePath = _.invert(this.getOption('appRoutes'))[routeName];
This could cause problem if multiple routes points to the same method.

Any thought is appreicated.

@rise2semi
Copy link

_.invert(this.getOption('appRoutes')) creates an object with the inverted keys and values. If routes object contains duplicate values, subsequent values overwrite property assignments of previous values.
In your case the result will be:

{
    'displayHome': 'home',
    'displaySecondLevel': 'home/aboutus/contactus/email',
}

As you can see we lost one route. This issue can be solved, but the main problem in other place.

Backbone returns to Marionette just routeName without any relation to a route path. In your case routeName is displaySecondLevel.

Even if we have all routes and their paths:

{
    'displayHome': 'home',
    'displaySecondLevel': 'home/:menu/:id',
    'displaySecondLevel': 'home/aboutus/contactus/email',
}

there is no way how to get the related route. I think the best solution for this is a route path will be returned by Backbone.

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

No branches or pull requests

3 participants