Closed bartosz-szymanski-dev closed 2 years ago
Good Morning, can you please post your logs or what u tried to do.
Good evening, surely, here are steps I took.
composer require friendsofsymfony/jsrouting-bundle
and recipies that were optional (they helped with configuration) - they added fos_js_routing: resource: "@FOSJsRoutingBundle/Resources/config/routing/routing-sf4.xml"
.php bin/console assets:install --symlink public
.app/config/packages/fos_js_routing.yaml
, where app directory stands for root of symfony's project.fos_js_routing: routes_to_expose: [ '^(.*)patient(.*)$', '^(.*)doctor(.*)$', '^(.*)front(.*)$' ]
.
This basically would expose routes with scheme like in those three entries.Here is my composer.json file:
{ "type": "project", "license": "proprietary", "minimum-stability": "dev", "prefer-stable": true, "require": { "php": ">=7.4", "ext-ctype": "*", "ext-iconv": "*", "ext-json": "*", "composer/package-versions-deprecated": "1.11.99.1", "doctrine/annotations": "^1.0", "doctrine/doctrine-bundle": "^2.3", "doctrine/doctrine-migrations-bundle": "^3.1", "doctrine/orm": "^2.8", "friendsofsymfony/jsrouting-bundle": "^2.7", "league/csv": "^9.6", "phpdocumentor/reflection-docblock": "^5.2", "sensio/framework-extra-bundle": "^5.1", "symfony/asset": "5.3.*", "symfony/console": "5.3.*", "symfony/dotenv": "5.3.*", "symfony/event-dispatcher": "5.3.*", "symfony/expression-language": "5.3.*", "symfony/flex": "^1.3.1", "symfony/form": "5.3.*", "symfony/framework-bundle": "5.3.*", "symfony/http-client": "5.3.*", "symfony/intl": "5.3.*", "symfony/mailer": "5.3.*", "symfony/mime": "5.3.*", "symfony/monolog-bundle": "^3.1", "symfony/notifier": "5.3.*", "symfony/process": "5.3.*", "symfony/property-access": "5.3.*", "symfony/property-info": "5.3.*", "symfony/proxy-manager-bridge": "5.3.*", "symfony/security-bundle": "5.3.*", "symfony/serializer": "5.3.*", "symfony/string": "5.3.*", "symfony/translation": "5.3.*", "symfony/twig-bundle": "^5.3", "symfony/validator": "5.3.*", "symfony/web-link": "5.3.*", "symfony/webpack-encore-bundle": "^1.11", "symfony/yaml": "5.3.*", "symfonycasts/verify-email-bundle": "^1.4", "twig/extra-bundle": "^2.12|^3.0", "twig/twig": "^2.12|^3.0" }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "^3.4", "phpunit/phpunit": "^9", "symfony/browser-kit": "^5.3", "symfony/css-selector": "^5.3", "symfony/debug-bundle": "^5.3", "symfony/maker-bundle": "^1.30", "symfony/phpunit-bridge": "^5.3", "symfony/stopwatch": "^5.3", "symfony/var-dumper": "^5.3", "symfony/web-profiler-bundle": "^5.3", "zenstruck/foundry": "^1.10" }, "config": { "optimize-autoloader": true, "preferred-install": { "*": "dist" }, "sort-packages": true }, "autoload": { "psr-4": { "App\\": "src/" } }, "autoload-dev": { "psr-4": { "App\\Tests\\": "tests/" } }, "replace": { "symfony/polyfill-ctype": "*", "symfony/polyfill-iconv": "*", "symfony/polyfill-php72": "*" }, "scripts": { "auto-scripts": { "cache:clear": "symfony-cmd", "assets:install %PUBLIC_DIR%": "symfony-cmd" }, "post-install-cmd": [ "@auto-scripts" ], "post-update-cmd": [ "@auto-scripts" ] }, "conflict": { "symfony/symfony": "*" }, "extra": { "symfony": { "allow-contrib": false, "require": "5.3.*" } } }
And now the question remains - why routes are not being exposed to file /app/public/js/fos_js_routes.json
when running bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json
?
Sorry for delay, please run only composer js-routes
Okay, I see... After running bin/console fos:js-routing:dump
I've got file created in place: app/web/js/fos_js_routes.js
and this file contains routes that are defined in my controllers. From what I can tell this file is JS. How to use it in Webpack?
I added in app.js :
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);
window.routing = Routing
And then in Vue files I call :
routing.generate('api_graphql_entrypoint')
I added in app.js :
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); window.routing = Routing
And then in Vue files I call :
routing.generate('api_graphql_entrypoint')
https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/issues/413
Okay, I see... After running
bin/console fos:js-routing:dump
I've got file created in place:app/web/js/fos_js_routes.js
and this file contains routes that are defined in my controllers. From what I can tell this file is JS. How to use it in Webpack?
Yes, u need to run yarn encore dev
any time u create new ajax route. Also if u didn't it this, u need to configure your "routing.yaml" adding a prefix to expose ur routes to ur json file.
My routing.yaml
framework:
router:
utf8: true
fos_js_routing:
routes_to_expose: [^ajax_.+]
route example
/**
* @Route("/credit/{type?}", name="ajax_get_credit", methods={"GET"}
*/
Remember u need to add to all routes ajax_
See my #413
I'm closing this issue because you've basically resolved it. Thank you!
I'm closing this issue because you've basically resolved it. Thank you!
You are welcome my man! Enjoy, anything u need reach me.
Hello, As we discussed in this issue, I'm mentioning @MaruanBO due to his request. Although I'm going to shortly describe what's happening in Symfony 5: I followed instructions for Symfony 4, reproduced each steps that has been required there, but I couldn't get the dump file having routes that has been specified in config file. Tried several times - always with the same result. Please help us guys, because Symfony 5 is on his way to release stable version and I wanted to practise a little bit with it.