-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with FOSJsRoutingBundle #97
Comments
Hey @dayze! Unfortunately, the JS in that bundle is not built to be used as a modern module :(. It's something we need to fix (in that bundle). But, here are a few solutions:
A) Continue to include the normal script tags for FOSJsRouterBundle in your HTML body (include them above any JS from Encore) B) Create a "fake" JS module, that simply uses the global Routing object // assets/Routing.js
module.exports = window.Routing; C) That's it! Now you can include this // assets/app.js
var Routing = require('./Routing.js');
Routing.generate('...'); Let me know if that helps! I'll leave this issue open, because we need to make this much easier. |
Hi ! |
Excuse me for the question that may seem trivial, but I'm just starting with Javascript. My question: Isn't it sufficient to write in the file where I need the Routing somthing like:
or use directly |
@Aerendir the benefit of keeping it only in a single module means that it is easier to upgrade your codebase once FOSJsRoutingBundle becomes more friendly (though I don't see a good way to be friendly to webpack without involving some dumping of routes, as loading routes in JSONP is precisely not friendly with webpack) |
@stof ok, it's a good point... I'll go this way! |
For getting autocomplete for methods of const Routing = window.Routing;
module.exports = {
generate(name, parameters = {}, absolute = false) {
return Routing.generate(name, parameters, absolute);
},
}; and name file with this export like |
the 2.2 version of FOSJsRoutingBundle should make things much easier, by supporting UMD for the router (you still need to load the routes) |
note that it would make the solution from #5 (comment) easier, not the solution with the global: // backend_router.js
const router = require('../vendor/friensofsymfony/js-routing-bundle/Resources/public/js/router.js');
// dumped_routes.json is the output file for the fos:js-routing:dump command
const routerConfig = require('../dumped_routes.json');
router.setRoutingData(routerConfig);
module.exports = router; |
well, if you install the bundle assets, accessing things from |
hmm indeed. |
How to handle routes during DEV when using the controller to deliver routes instead of using the dumped ones? I hacked something together by exposing Is there a better solution? |
The @stof solution wasn't working for me. I think it's because I'm using the version 1.6. An alternative solution I found was to use the "webpack-merge-and-include-globally" on my webpack.config.js.
and then I can simply use the file in my template:
|
Whats the best solution on a dev environment ? I don't really want to dump routes every time I add a new route using the above solution . |
I'm still stuck with my hacky solution described in #97 (comment). |
Ok I ended up using script tags, creating a Routing.js file with
This turns out to be the most practical way to use it for me. |
Hi!! 1 - https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/installation.html I don't user webpack encore and I don't want to using this. I question you this, because I do everything writting exist inside in the manual but without success .. The question is, how to use this Bundle in my Project without webpack encore ??? Somebody help me ?? |
@marcckku The three URLs you gave detail how to use the FOSJsRoutingBundle without Encore. This thread is about using it with Encore. |
Closing as resolved. |
I'm struggling to make FOSJSRoutingBundle works with webpack encore.
I've imported router.js from
web/bundles/fosjsrouting/js/router
And I get the error
router.js:8:480 TypeError: undefined is not an object (evaluating 'k.navigator')
It works when I include it directly into my twig template.
Is there a proper way to make it work with webpack ?
The text was updated successfully, but these errors were encountered: