Closed picks44 closed 6 years ago
how are you providing your routes ? Are you dumping the route file, or are you loading them from the controller ?
/**
* @Route("/ajax/myroute", name="ajax_myroute", options={"expose"=true})
*/
public function myRouteAction(Request $request)
{
// my code
}
Then within a JS file
const routes = require('../../../web/js/fos_js_routes.json');
import Routing from '../../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';
Routing.setRoutingData(routes);
$.ajax({
url: Routing.generate('ajax_myroute'),
method: "POST",
data: data,
success: function (response) {
// some code
}
});
well, when dumping routes, the base path is included in the dumped file too. So this requires configuring the router properly in the CLI (the incoming request cannot be used to guess it), as explained in the doc of the bundle command, which links to http://symfony.com/doc/4.1/console/request_context.html#configuring-the-request-context-globally
If your dev env is relying on having /app_dev.php
in the URL, you need to router.request_context.base_url
param (but not in the base_path
one, which is only the base path to the document root)
So adding the following in config_dev.yml should solve this issue right?
parameters:
router.request_context.base_url: /app_dev.php
Working thanks!
How come I cannot generate a
http://myproject.local/app_dev.php/myroute
with the bundle ? I tried several config and the route is always generated ashttp://myproject.local/myroute
whereas I work in Dev mode...I use Webpack Encore and dump the files using
yarn run encore dev
Is there something I missed ?