routing
routing copied to clipboard
Action parameters do not work correctly for null value
Version: 3.1.0
Steps To Reproduce
Latte
{block content}
{$type}
{link this type: null}
{link this type: articles}
{link this type: random}
{/block}
Router
public static function createRouter(): RouteList
{
$router = new RouteList;
$router->addRoute('articles', [
'presenter' => 'Home',
'action' => 'default',
'type' => 'articles'
]);
$router->addRoute('<presenter>/<action>[/<id>]', 'Home:default');
return $router;
}
Output
articles
/articles
/articles
/?type=random
Curl output curl -I http://localhost:9997/
HTTP/1.1 301 Moved Permanently
Host: localhost:9997
Location: http://localhost:9997/articles
Expected Behavior
articles
/
/articles
/?type=random
This can be fixed by adding the following code before article route.
$router->addRoute('/', [
'presenter' => 'Home',
'action' => 'default',
'type' => null,
]);
but I think it's undesirable behavior
This should work:
$router->addRoute('articles ? type=<type>', [
'presenter' => 'Home',
'action' => 'default',
'type' => 'articles'
]);
It's not working. Still need to add router with null