Change default module route

+
0
-

I have updated the app/Router file as follows, and this works for http://example.com/default/default, however, does not work for http://example.com/ and gives an error.

Nette\Application\BadRequestException #404
No route for HTTP request

My goals is to have a routing map for <module_name>/<presenter>/<action>/<id> with the default presenter, and action being Default.

<?php

declare(strict_types=1);

namespace App\Router;

use Nette;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;

final class RouterFactory
{
        use Nette\StaticClass;

        public static function createRouter(): RouteList
        {
                $router = new RouteList;
                ### $router->addRoute('<presenter>/<action>[/<id>]', 'Homepage:default');
                $router->addRoute('<module>/<presenter>/<action>[/<id>]', 'Default:Default:default');
                return $router;
        }
}
?>
MajklNajt
Member | 498
+
0
-

You must specify presenter and action as optional

<?php
$router->addRoute('<module>[/<presenter>[/<action>[/<id>]]]', 'Default:Default:default');
?>
+
0
-

The error persists.

Nette\Application\BadRequestException #404
No route for HTTP request

<?php

declare(strict_types=1);

namespace App\Router;

use Nette;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;

final class RouterFactory
{
        use Nette\StaticClass;

        public static function createRouter():RouteList
        {
                $router = new RouteList;
                $router->addRoute('<module>[/<presenter>[/<action>[/<id>]]]', 'Default:Default:default');
                return $router;
        }
}
?>
+
0
-

Changing the route to this:

<?php
$router->addRoute('[<module>[/<presenter>[/<action>[/<id>]]]]', 'Default:Default:default');
?>

With the module as optional also, then forwards to http://example.com/default/default.

Is it possible to not show the /default/default in the url?

Thanks,
Kevin

Last edited by kevin.waterson@gmail.com (2019-10-29 09:38)