Can custom routes be added per module

+
0
-

I have nette set up for some modules.
Each module in its own directory, with presenters and templates.

Eg: Blog
    Blog/presenters/DefaultPresenter
    Blog/templates/default.latte

Can I add custom routes in separate file in the Blog directory?
Eg: Blog/Routes/my_routes.php
or something?

CZechBoY
Member | 3608
+
+1
-

You can include another router factory in main router factory.

+
0
-

CZechBoY wrote:

You can include another router factory in main router factory.

extend the router factory?

So, something like:

<?php

declare(strict_types=1);

namespace App\Router;

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


final class RouterFactory
{
        use Nette\StaticClass;

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

        public static function createBlogRouter(): RouteList
        {
                $router = new RouteList;
                $router->addRoute('[Blog[/Admin[/category[/edit[/<id>]]]]]', 'Blog:Admin:editCategory');
                return $router;
        }
}
?>

And call this function from the config

router: App\Router\RouterFactory::createRouter
        App\Router\RouterFactory::createBlogRouter