Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

nette-routing

БесплатноБез исполняемых скриптовНе проверен

Invoke before writing or modifying a router, a RouterFactory or any URL mask in Nette. Use for RouteList, addRoute(), route masks (optional `[...]` parts…

netteот nette★ 47 звёзд на GitHub

Об этом скилле

Nette Routing

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.

Order governs link GENERATION, not just matching

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.

Mask grammar

$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
  • A defaulted parameter becomes optional only if everything after it is optional too: '<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>.
  • Query parameters can be renamed but not validated: in 'product ? id=<productId>' a regex would be silently discarded.
  • A parameter in the metadata array but not in the mask is constant: unchangeable from the query string, and a link passing a different value makes the route decline and fall through – that is how addRoute('tos', ['presenter' => 'Article', 'id' => 123]) works.

RouteList, modules, nesting

$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.
  • Without 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).

One-way routes

$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.

Filters

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->add
Полный SKILL.md на GitHub

Установить nette-routing в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл nette-routing?

Invoke before writing or modifying a router, a RouterFactory or any URL mask in Nette. Use for RouteList, addRoute(), route masks (optional `[...]` parts, `<param regex>` constraints, defaults in the mask), withModule()/withDomain()/withPath(), pretty URLs and slugs, one-way routes for retired URLs, Route::FilterIn/FilterOut/FilterTable/FilterStrict, general filters under the `''` key, fixed parameters, SimpleRouter, the `routing:` NEON section, and canonical-URL redirects (canonicalize(), $autoCanonicalize). Also trigger for "wrong URL is generated", "link points to the wrong route", dots in URLs of a modular app, unexpected 301 redirect loops, or the Tracy routing panel. Not for `n:href`/`{link}` syntax (latte-templates) nor signal links (nette-components).

Как установить скилл nette-routing?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл nette-routing запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить nette-routing с