Comments (6)
I'm not sure it's related to the JsRoutingBundle, and I don't want to add tweaks/hacks for other bundles that are not more than widely used.
from fosjsroutingbundle.
Of course I understand, but by default, the router uses the following to determine which locale to use for route generation:
1 . the _locale parameter which was passed to the generate() method
2 . use the _locale parameter which is present in the request context
3 . use the configured default locale
But with the JS generate() function all of that seems to be ignored. I don't understand why ...
from fosjsroutingbundle.
@z3yo The I18nRoutingBundle extends the Symfony router to choose the route name according to the locale (prepending it). The JS code is not changed when including the bundle. So you would need to use the route name generated with the locale in it.
from fosjsroutingbundle.
I replaced JMSi18nRoutingBundle by BeSimpleI18nRoutingBundle, it process with a different way and works well with FOSJsRoutingBundle.
from fosjsroutingbundle.
I was having the same issue as @z3yo because I was loading the router files in the "assetic" way in my base template:
{% javascripts output='js/routing.js'
'bundles/fosjsrouting/js/router.js'
'js/fos_js_routes.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
This was not working for me even after dumping the routes with the fos:js-routing:dump
command, since all i18n routes were prefixed with "LOCALE__RG__". and using Routing.generate('my_route')
inside my javascripts wasn't findindg the appropriate route.
But then I thougt I could give a try at loading the fos_js_router resources the "traditional" way:
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
and it's working like a charm now. I don't even need to dump the js routes anymore as the fos.Router.setData
method takes care of looking for exposed routes as far as I understand. Now I can successfully use Routing.generate('my_route')
inside any js script and it just creates the route in the currently selected locale.
Hope it helps.
from fosjsroutingbundle.
fos.Router.setData
is just the JSONP callback. Taking care of exposed routes is done server-side (and the different between the controller and the command looks weird)
from fosjsroutingbundle.
Related Issues (20)
- webpack-inject-plugin.loader.js?id=webpack-inject-module-1!" contains a reference to the file "fos-router"
- Wrong route in dev env. missing index.php in route HOT 2
- Exception when a route name is a parsable number
- Error: spawn bin/console ENOENT HOT 7
- webpack-inject-plugin > loader-utils vulnerability HOT 4
- Routing isn't finding any routes HOT 2
- webpack problem /FosRouting.js" contains a reference to the file ....
- Symfony 6.3 deprecations
- Symfony 6.3 deprecations when dump routes HOT 1
- Overwriting php location causes console errors that --php is not a valid options
- Document how to install using AssetMapper HOT 10
- Session handling is incompatible with stateless routes introducted with Symfony 6.3
- Run webpack encore and execute php fos:js-routing:dump separately HOT 2
- Support Symfony 7 HOT 6
- 3.4.0 not working with Symfony 6.4 HOT 11
- TS2732: Cannot find module './routes.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
- Is it possible to `npm install` | `yarn install` the router? HOT 1
- modify dump command to generate export call in js routes file.
- glob-parent package vulnerability
- Deprecation notice on Symfony's DependencyInjection/Extension
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fosjsroutingbundle.