SSR routing

The classic route component

SSR endpoints behave similar to API endpoints in a lot of ways. Any component controller that has a method init automatically is a valid route.

1. Create a route endpoint
neoan3 new component myHome -t:route

Note!

Regardless of component type, endpoints resolve kebab case. The full url of this example would therefore be
http://localhost:8080/my-home

2. Handle deep routes
You can easily read query-strings by using the global sub(int $number) function. While 0 would be the component itself, 1 would be the next URL part. sub(int $number) return false if not set.

Examples

Url Sub-part Result
/my-home sub(0) "my-home"
/my-home sub(1) false
/my-home/today sub(1) "today"
/my-home/today/123 sub(2) "123"

3. Handle 404
If you offer SSR content, you likely want to have a look at default.php and make changes to th constant default_404. It accepts a value used to determine which component to render in a 404 case.

4. Handle home page
Usually a project has a default (home) page. You can set it in default.php by changing the value of default_ctrl