This bundle allows you to expose your Symfony routes and use them in your webpack managed JavaScript code. It allows you to easily integrate the functionality of the FOSJsRoutingBundle into webpack modules.
composer require xactsystems/js-routing-bundle
For Symfony 3.4 use:
composer require xactsystems/js-routing-bundle:^3.4
// templates/base.html.twig
{{ include("@XactJSRouting/js-routing.html.twig") }}
// assets/js/App.js
// Import the JS routing scripts
import '../../vendor/xactsystems/js-routing-bundle/assets/js-routing.js';
The actual path to the js-routing.js file may not be exactly as shown, you may need to adjust this for your own project.
// Get the URL of your routes
let url1 = Routing.generate('home');
let url2 = Routing.generate('some-other-route', {id: myLocalId, state: myLocalState});
// app/AppKernel.php
public function registerBundles()
{
// You many need to do this to get the render(controller()) Twig method working for XactJSRoutingBundle
$_ENV["APP_ENV"] = $this->getEnvironment();
And for the Symfony Serializer component:
// app/config/config.yml
framework:
...
# If you haven't already enabled the Symfony Serializer
serializer: { enabled: true }
- Ian Foulds as the creator of this package.
- William DURAND as author of the FOS bundle.
- Julien MUETTON (Carpe Hora) for the inspiration.
This bundle is released under the MIT license. See the complete license in the bundle: