nette / routing

Nette Routing: two-ways URL conversion
https://doc.nette.org/routing
Other
231 stars 3 forks source link

Action parameters do not work correctly for null value #15

Open MartkCz opened 3 months ago

MartkCz commented 3 months ago

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
MartkCz commented 3 months ago

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

dg commented 3 months ago

This should work:

$router->addRoute('articles ? type=<type>', [
    'presenter' => 'Home',
    'action' => 'default',
    'type' => 'articles'
]);
MartkCz commented 3 months ago

It's not working. Still need to add router with null