I'm trying use FOSJsRoutingBundle
to generate urls from symfony routes.
I follow the doc.
I include the files into my base.html.twig
:
{% block scripting %}
...
<script type="text/javascript" src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
...
{% endblock %}
And don't get inclusion error. But the try to generate an url fails:
console.log(Routing.generate('usuarios_crear'));
GET http://appsmanantiales.local/web/app_dev.php/js/routing?callback=fos.Router.setData 500 (Internal Server Error) listar:131 Uncaught Error: The route "usuarios_crear" does not exist. router.js:9
In my routing.yml
I have:
usuarios_crear:
pattern: /AbmUsuarios/crear
defaults: { _controller: AbmBundle:Usuario:crear }
options:
expose: true
And the route is in php app/console fos:js-routing:debug
list:
usuarios_crear ANY ANY ANY /AbmUsuarios/crear
Any ideas?
Your code is great.
I suggest that you open an issue here, this is very likely to be a bug as you're not the only one to have that issue.
It's probably easier than you think.
Visit the page generated here: {{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}
it should have json-encoded list of your exposed routes. If your route is there you're good.
How check when you execute console.log(Routing.generate('usuarios_crear'));
The document should be ready before you try that. So make sure it is (i.e. jQuery's $('document').ready()
).
Reading the Github issues, found this where the author suggest not use the dev-master version. I do a downgrade to "@stable", and works (for now). The composer.json line may be:
"friendsofsymfony/jsrouting-bundle": "@stable"
For more detail: The full install guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With