friendsofsymfony/jsrouting-bundle
Router component. It seamlessly integrates with Symfony’s routing system, making it ideal for projects already using Symfony’s routing (e.g., symfony/routing, symfony/framework-bundle)._csrf_token, role-based access) since routes are pre-generated server-side. No runtime security bypass risks.fos_js_routing_js Twig function to render JS routes. Compatible with Symfony’s asset system (e.g., assets:install).fos_js_routing.route_generator service).| Risk Area | Mitigation Strategy |
|---|---|
| Route Cache Invalidation | Use Symfony’s cache system (e.g., cache:clear) or event listeners to invalidate JS route cache on route changes. |
| Frontend Framework Quirks | Test with target frameworks (e.g., React Router, Vue Router) to ensure route parameter handling matches expectations. |
| Dynamic Routes | Ensure dynamic routes (e.g., {id}) are properly escaped in JS to avoid XSS (bundle handles this by default). |
| Bundle Deprecation | Monitor Symfony’s core routing improvements (e.g., symfony/ux-router) for future migration paths. |
| Performance Overhead | Profile route dump size; use fos_js_routing.route_filter to exclude unnecessary routes. |
_method, _locale) that need special handling?| Component | Compatibility |
|---|---|
| Symfony | Core bundle; works with Symfony 5.4+ (tested up to 7.x). |
| PHP | Requires PHP 8.0+ (for Symfony 6+). |
| Frontend Frameworks | Agnostic; works with vanilla JS, React, Vue, Angular, etc. |
| Asset Pipelines | Compatible with Webpack Encore, Vite, Symfony AssetMapper. |
| Caching | Leverages Symfony’s cache system (APCu, Redis, filesystem). |
| Database | No direct DB dependency; routes are generated from YAML/XML/PHP configs. |
composer require friendsofsymfony/jsrouting-bundle
config/bundles.php:
return [
// ...
FriendsOfSymfony\JsRoutingBundle\FriendsOfSymfonyJsRoutingBundle::class => ['all' => true],
];
base.html.twig):
{{ fos_js_routing_js('app_routes') }}
app.js):
import routes from './routes.json'; // or via script tag
// Before
const url = '/product/123';
// After
const url = routes.generate('product_show', { id: 123 });
<Route path={routes.generate('product_show', { id: ':id' })} element={<Product />} />
phpunit).{_locale}) and defaults._csrf_token).?page=1 vs. /page/1).fos_js_routing.route_generator to customize route generation.translator and _locale requirements.routes.generate().route_filter.fos_js_routing.route_filter to manage route exposure granularly.routes.json with php bin/console debug:router).id vs. slug).routes.json size; exclude unused routes.routes.json via CDN with cache headers (e.g., Cache-Control: public, max-age=31536000).| Scenario | Impact | Mit
How can I help you explore Laravel packages today?