0

I try to use javascript routing in Symfony according to this tutorial: https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html

Here is my code:

...
  "render": function (data, type, row, meta) {
  return Routing.generate('get-file', { fileId: data });

}
...

Amd the scripts:

<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('get-file', { callback: 'fos.Router.setData' }) }}"></script>
<script>
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);
Routing.generate('rep_log_list');
</script>

But I get the error:

An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("fileId") to generate a URL for route "get-file".").

1
  • This question is similar to: Generating routes in javascript with Twig and Symfony2. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Nov 28, 2024 at 10:17

1 Answer 1

3

You don't need a bundle to do that.
Generate the route with a default parameter, then replace it with your JavaScript variable.

let route = "{{ path('get-file', { filedId: 'fileId_' }) }}";
route = route.replace('fileId_', yourVariable);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.