FosJSRoutingBundle, route does not exist

  fosjsroutingbundle, symfony

I’m trying to generate URL in my Javascript but I can’t due to this error:

Error: The route “my_route” does not exist.

I don’t know why but the route is not recongnized…

What I did:

1) Get the bundle by composer
2) Published the assets :

php bin/console assets:install --symlink public

3) Use this in JS:

Routing.generate("my_route")

4) And then, this in my controller:

    /**
     * @Route("/route/to/route",  options = { "expose" = true }, name="my_route")
     * @param Request $request
     * @return Response
     */
    public function my_route(Request $request){ 
some things...  };

So, it’s not working…

I checked the JS dependencies that are loaded in the page:

    <script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script> 
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>

The first work but the second return error 404… Why ?

Regards

Source: Symfony Questions

One Reply to “FosJSRoutingBundle, route does not exist”

LEAVE A COMMENT