Small update, make router dynamic with prefixes.

This commit is contained in:
2026-05-29 11:08:19 +02:00
parent 3c232440c2
commit a78a95dd8e
2 changed files with 93 additions and 26 deletions
+68 -11
View File
@@ -114,24 +114,81 @@ return [
];
```
Routes beginning with:
## Route Prefixes
```text
api/
```
Routes can be mapped to different source directories using prefixes.
are loaded from:
```text
src/api/
```
Everything else is loaded from:
By default:
```text
src/views/pages/
```
is used for normal pages.
The router also supports configurable route prefixes:
```php
$route_bases = [
'api/' => ROOT . '/src/api',
];
```
Example:
```php
'/api/users' => 'api/users.php',
```
loads:
```text
src/api/users.php
```
while:
```php
'/about' => 'about.php',
```
loads:
```text
src/views/pages/about.php
```
### Adding A New Route Type
Create a new directory:
```text
src/docs/
```
Then add a prefix:
```php
$route_bases = [
'api/' => ROOT . '/src/api',
'docs/' => ROOT . '/src/docs',
];
```
Now:
```php
'/docs/getting-started' => 'docs/getting-started.php',
```
will load:
```text
src/docs/getting-started.php
```
No router changes required.
---
## Adding A New Page