Small update, make router dynamic with prefixes.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user