Symfony 4 – Webpack-encore use FosJsRouting : Routing is not defined

I try to use FosJsRouting with Webpack-encore in my Symfony 4 project.

I did :

1.

composer require friendsofsymfony/jsrouting-bundle

2.

php bin/console assets:install --symlink public

3.

php bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json

And in my app.js :

// FosJsRouting

const routes = require('../../public/js/fos_js_routes.json');
import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';
Routing.setRoutingData(routes);

Now, if in the app.js I do a console.log(Routing); I get the object in the console.

On the other hand, impossible to use it in my templates.

I have the following error:

Uncaught ReferenceError: Routing is not defined

I do not understand because my other packages work very well, but not the Routing

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *