/symfony-ux-skills:ux-routerfrom symfony-ux-skills
Generates Symfony route URLs in JavaScript with the same result as Twig's path() and url() functions. Type-checked in TypeScript. Useful when JavaScript builds URLs from runtime data.
Ships in symfony-ux-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Generate the URLs of your Symfony routes in JavaScript, with the same result as the path() and url() Twig functions. Exposed routes are dumped to var/routes/; with TypeScript, route names and parameters are type-checked.
Since Symfony UX 3.6+. The package is experimental: its API may still change.
Prefer passing URLs from Twig (a Stimulus value, a data-* attribute) when a controller needs one or two fixed URLs. Reach for UX Router when JavaScript builds URLs from data it only knows at runtime.
composer require symfony/ux-router
Flex creates the router module:
// assets/router.js (rename to router.ts for type-checking)
import { createRouter } from '@symfony/ux-router';
import { routes, defaultLocale } from '../var/routes/index.js';
export const { path, url } = createRouter({ routes, defaultLocale });
| Asset pipeline | Extra step |
|---|---|
| AssetMapper | None: the bundle registers the dump directory and the @symfony/ux-router importmap entry |
| Reprise (Vite / Rsbuild) | npm install --force, then restart the dev server |
| Webpack Encore | npm install --force, then restart Encore |
No route is exposed by default. List name patterns:
# config/packages/ux_router.yaml
ux_router:
routes:
- 'app_*' # wildcard
- '!app_admin_*' # leading ! excludes
A single route can opt in or out with the expose option, which always wins over the patterns:
#[Route('/search', name: 'search', options: ['expose' => true])]
public function search(): Response
A localized route is exposed when its name (app_about) or one of its variants (app_about.en) matches.
Exposed routes are readable by anyone who loads your JavaScript, and they all end up in the bundle. Keep the list to what JavaScript calls; avoid '*', which also exposes internal routes such as the profiler's.
import { path, url } from './router.js';
path('app_blog_show', { slug: 'hello', _query: { page: 2 }, _fragment: 'comments' });
// '/blog/hello?page=2#comments'
path('app_blog_show', { slug: 'hello' }, true);
// relative path: 'blog/hello'
url('app_blog_show', { slug: 'hello' });
// 'https://example.com/blog/hello'
url('app_blog_show', { slug: 'hello' }, true);
// network path: '//example.com/blog/hello'
Query parameters go in _query. Optional parameters equal to their default are omitted, as in PHP.
Call a localized route by its base name; the current locale picks the variant:
path('app_about'); // '/about' when <html lang="en">
path('app_about', { _locale: 'fr' }); // '/a-propos'
Locale resolution order: the _locale parameter of the call, the _locale of the context given to createRouter(), the lang attribute of <html> (fr-FR becomes fr_FR), the defaultLocale option (the dump exports framework.default_locale), then en.
Host, scheme and port come from the current page. Override them with context, for instance for an app served from a sub-directory:
export const { path, url } = createRouter({
routes,
context: { baseUrl: '/my-app' },
});
RouteNotFoundError, MissingMandatoryParametersError and InvalidParameterError are exported by @symfony/ux-router and thrown in the same cases as in PHP:
import { RouteNotFoundError } from '@symfony/ux-router';
try {
path('app_unknown');
} catch (error) {
if (error instanceof RouteNotFoundError) {
// ...
}
}
Requirements are checked as JavaScript regexes ([^/]+ instead of [^/]++); a requirement JavaScript cannot express, such as \A or [[:alpha:]], is left to the PHP router.
Routes are dumped on cache warmup, and again in dev on the next request after a route changes. To refresh only the JavaScript routes:
php bin/console ux:router:warm-cache
# config/packages/ux_router.yaml
ux_router:
# Where routes and TypeScript types are dumped (update assets/router.js if changed)
dump_directory: '%kernel.project_dir%/var/routes'
# Dump TypeScript types next to the routes
dump_typescript: true
# Route name patterns to expose, "!" to exclude
routes: []
AssetMapper ignores the TypeScript types, so they can be skipped in production there:
when@prod:
ux_router:
dump_typescript: false
Keep them with Reprise or Encore and TypeScript: the build type-checks against them.
RouteNotFoundError for an existing route: the route is hidden from JavaScript. Check the routes patterns (an exclusion may match) or add options: ['expose' => true].cache:warmup or run ux:router:warm-cache.context to createRouter().ux:router:warm-cache after adding a route.symfony/ux-router on Packagist.path() in a controller to build URLs from targets or valuesTurbo.visit(path('app_blog_show', { slug })) navigates with Drivevar/translations/, trans() in JavaScript)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub smnandre/symfony-ux-skills --plugin symfony-ux-skills20 skills in this plugin
/live-componentSymfony UX LiveComponent: live search, live filters, dependent selects and form validation as users type. Use for reactive PHP and Twig components, #[AsLiveComponent], LiveProp, LiveAction, data-model, loading states, emit/listen, lazy rendering and LiveResponse downloads./stimulusSymfony UX Stimulus: JavaScript behavior for dropdowns, tabs, modals, clipboard buttons and third-party widgets. Use for StimulusBundle, data-controller, data-action, targets, values, outlets, lazy controllers and Twig stimulus_* helpers./symfony-uxSymfony UX: choose and combine packages for a Symfony frontend. Use when deciding between Stimulus, Turbo, TwigComponent and LiveComponent, or fitting several Symfony UX packages into the same feature. Prefer the dedicated skill for a task that fits one package./turboSymfony UX Turbo: Turbo Frames for partial navigation and form submissions, Turbo Streams for multiple updates and Mercure broadcasts, and Turbo Drive for links and forms. Use for turbo-frame, turbo-stream, twig:Turbo, TurboFrame, TurboStreamResponse, turbo_stream_from and #[Broadcast]./twig-componentSymfony UX TwigComponent: reusable Twig buttons, cards, alerts and design system components. Use for twig: tags, #[AsTwigComponent], props, blocks, attributes.defaults(), anonymous components, computed properties, provide()/inject() and html_cva./ux-autocompleteSymfony UX Autocomplete: searchable selects and Ajax suggestions for large Symfony form lists. Use for EntityType, ChoiceType, Tom Select, the autocomplete option, #[AsEntityAutocompleteField], #[AsAutocompleteField], AutocompleterInterface, extra_options and tom_select_options.Other plugins' skills for the same job