/nette:nette-routingfrom nette
Guides writing and debugging Nette routes, RouteList, URL masks, filters, and canonical redirects. Helps fix wrong URL generation, link routing, 301 loops, and Tracy panel issues.
Ships in nette. 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.
A route is bidirectional: the same object matches an incoming URL and generates links, and almost
every routing bug comes from forgetting the second direction. Related skills: nette-architecture
(RouterFactory, lifecycle), nette-configuration (registering it), nette-components (signal
links), latte-templates (n:href/{link}). Verified against nette/application 3.3.0 and
nette/routing 3.1.3.
RouteList::constructUrl() walks the routes in declaration order and returns the URL from the first
route that can build one – so a catch-all placed first silently hijacks every link, with no error:
$router->addRoute('admin/<presenter>/<action>', 'Admin:Default:default'); // WRONG order:
$router->addRoute('rss.xml', 'Feed:rss'); // link to Feed:rss generates '/admin/feed/rss'
Specific first, catch-all last. The canonical URL of a page is whatever the first non-one-way matching route generates, so the order also decides where canonicalization redirects.
$router->addRoute('chronicle/<year=2020>', 'History:show'); // default inside the mask
$router->addRoute('<presenter>/<action>[/<id \d+>]', 'Home:default'); // optional part + regex
$router->addRoute('<path .+>', 'File:serve'); // default pattern is [^/]+; only .+ eats slashes
$router->addRoute('//<lang>.example.com/<presenter>', /* ... */); // host part needs the // prefix
'<presenter=Home>/<action=default>/<id=>' equals
'[<presenter=Home>/[<action=default>/[<id>]]]', hence the trailing slash. Write the brackets
yourself – '[<presenter=Home>[/<action=default>[/<id>]]]' – to drop it.
Generation prefers the shortest variant; [!...] keeps an optional part in generated URLs while
still accepting URLs without it ('<name>[!.html]' generates /hello.html).%basePath%, %host%, %domain%, %sld%, %tld% are substituted only in //-masks, and
%basePath% is matched with its surrounding slashes – write //www.%domain%/%basePath%/<presenter>.'product ? id=<productId>' a regex would be
silently discarded.addRoute('tos', ['presenter' => 'Article', 'id' => 123]) works.$router = new Nette\Application\Routers\RouteList;
$router->withModule('Front')
->addRoute('rss.xml', 'Feed:rss') // presenter becomes Front:Feed
->addRoute('<presenter>/<action>', 'Home:default')
->end()
->withDomain('admin.%domain%')->withModule('Admin')
->addRoute('<presenter>/<action>', 'Dashboard:default');
return $router; // the ROOT, not the chain result
withModule()/withDomain()/withPath() create and attach a new child list and return it, not
$this; end() returns the parent. Keep the root in a variable –
return (new RouteList)->withModule('Front')->addRoute(...) returns the child and loses the siblings.withModule() (or a fixed module parameter) the full presenter name lands in the URL,
where each : becomes a dot and each PascalCase boundary a dash: Front:Admin:ProductList shows up as
front.admin.product-list. Dotted URLs mean a missing withModule().
<module> in a mask captures the whole module path, up to the last colon, and
Nette: presenters (Nette:Micro, Nette:Error) are never prefixed.$router[] = new Route(...) is deprecated and emits E_USER_DEPRECATED – use
addRoute()/add(), which return static; prepend() returns void. Add a
Nette\Application\Routers\Route, never a Nette\Routing\Route – only the former knows
presenter/action/module inflection (importing the latter for Route::Value constants is fine).$router->addRoute('product-info', 'Product:detail', oneWay: true); // old URL, accepted only
$router->addRoute('product/<id>', 'Product:detail'); // canonical, generates links
oneWay is int|bool. One-way routes are skipped while the generation cache is built, so such a route
can never produce a URL; the old address is matched and then 301-redirected by canonicalization. Router::ONE_WAY still
works but is @deprecated on master – prefer the named argument.
Route::FilterIn converts URL -> application, FilterOut back; both take either one parameter (a
string) or, under the empty key '', the whole parameter array. Route::FilterTable is a declarative
url => app map for one parameter and Route::FilterStrict => true makes it reject unlisted values.
$router->addRoute('article/<id [0-9]+>[-<slug>]', [
'presenter' => 'Article', 'action' => 'detail',
'' => [ // general filter: sees all parameters at once
Route::FilterOut => fn(array $p): array => $p + ['slug' => $slugs->get((int) $p['id'])],
],
]);
FilterIn runs before the general one, on
output the general FilterOut runs before the per-parameter one, so inside a general filter
presenter/action are always PascalCase/camelCase.presenter, action and module already carry filters converting PascalCase/camelCase to
kebab-case; write defaults in the application form, <presenter=ProductEdit>, not
<presenter=product-edit>.FilterIn returning null rejects the route (matching falls through to the next one) unless the
parameter has a default; FilterStrict behaves the same.FilterTable keys may map to one value; the last wins as canonical, because the reverse
table is array_flip()ped. Adding a slug to every link is likewise a
FilterOut-only job – no template changes; cache the lookup, one page generates the same link often.Presenter::canonicalize() regenerates the URL through the router and 301-redirects if it differs from
the current one. It runs after the action phase and before signals (see nette-architecture for
the full lifecycle) – an action can still change parameters before it fires, a signal handler cannot.
$this->autoCanonicalize = false and call $this->canonicalize() where it suits; switch() inside an
action disables it automatically.VARYING flag, which gives 302; nothing in the framework sets it – use $this->getRequest()->setFlag(Nette\Application\Request::VARYING) when
the canonical URL depends on the user or locale.FilterOut that is
not the exact inverse of what the mask accepts.- App\Core\RouterFactory::createRouter), or for query-string URLs
(?presenter=…&action=…) just - Nette\Application\Routers\SimpleRouter('Home:default').
routing: cache: true serializes the compiled router into the DI container, but only works when the
factory takes no arguments and every route is serializable — a closure in FilterIn/FilterOut
(the slug pattern above) makes compilation fail with Unable to cache router due to error: Serialization of 'Closure' is not allowed. Use FilterTable or a callable array instead, or leave
the cache off.$presenter->getHttpRequest()->getUrl() is the raw incoming URL, $presenter->getRequest() is the
Nette\Application\Request the router produced – comparing them says at once whether the fault is in
matching or in link generation.The full Nette documentation for this topic is bundled with the plugin. Read a page when you need details beyond this skill:
routing: sectionWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub nette/agent-plugins --plugin nette20 skills in this plugin
/frontend-developmentProvides frontend development guidelines for Nette. Use when working with Vite, SCSS, JavaScript/TypeScript, Nette Assets ({asset} tag, asset mapping), ESLint with @nette/eslint-plugin, Naja AJAX library, frontend entry points, npm packages in Nette context, Tailwind CSS with Latte templates, nette-forms npm package, HMR, build commands (npm run dev/build), or passing data from PHP to JavaScript./latte-templatesInvoke before creating or modifying .latte files, even for single-line changes. Provides Latte syntax, tags, filters, n:attributes, layouts, template inheritance, AJAX snippets, extensions, and Nette integration. Also trigger when user mentions Latte by name./neon-formatOther plugins' skills for the same job