FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 261 forks source link

_locale parameter not injected automatically #295

Closed abienvenu closed 7 years ago

abienvenu commented 7 years ago

When exposing a route with {_locale} inside, the locale parameter should be injected automatically (see #84). This feature was working fine with FOSJsRoutingBundle version 1.6.0, but is not working anymore with version 1.6.1, 1.6.2 and 1.6.3. We get this javascript error: Error: The route "dinosaurs_index" requires the parameter "_locale".

tobias-93 commented 7 years ago

Hi @abienvenu,

I'm sorry you're experiencing problems. When I compare 1.6.0 (last known good) with 1.6.1 (first experiencing problems): https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/compare/1.6.0...1.6.1 I cannot find any change that would cause your problems. Could you provide me with an example of your routing as generated by 1.6.0, and one as generated by 1.6.1?

Thank you.

abienvenu commented 7 years ago

Thank you for your concern. To be more precise, the problem appeared from commit 79bfd646ce5f50f07ffcc173e8bec79bda7df82a file router.js.

As requested, here is the routing generated in 1.6.0:

fos.Router.setData({
    "base_url": "",
    "routes": {
        "dinosaurs_index": {
            "tokens": [["text", "\/dinosaurs\/index"], ["variable", "\/", "[^\/]++", "_locale"]],
            "defaults": [],
            "requirements": [],
            "hosttokens": []
        },
    },
    "prefix": "",
    "host": "www.dev.dinosaurs.fr",
    "scheme": "https"
});

And with 1.6.1:

fos.Router.setData({
    "base_url": "",
    "routes": {
        "dinosaurs_index": {
            "tokens": [["text", "\/dinosaurs\/index"], ["variable", "\/", "[^\/]++", "_locale"]],
            "defaults": [],
            "requirements": [],
            "hosttokens": [],
            "methods": [],
            "schemes": []
        },
    },
    "prefix": "",
    "host": "www.dev.dinosaurs.fr",
    "scheme": "https"
});
abienvenu commented 7 years ago

With further investigation, I found that locale injection is not implemented by FOSJsRoutingBundle itself, but by custom JS code in my project. The recent change in FOSJsRoutingBundle implementation made our custom code to fail. So I guess this is a not a FOSJsRoutingBundle issue.

tobias-93 commented 7 years ago

@abienvenu if you're using the snippet as shared by @bobvandevijver in https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/issues/84#issuecomment-34876126, you can fix it by replacing the routes.a to routes.b. This works in our project. However, as this is not an issue in this bundle, I'm closing this issue.