Something has to connect a request for /blog/one-route-for-every-page to an entry and a view. One way is a route per content type in routes/web.php. The other is one catch-all owned by the CMS. Mainstay takes the catch-all and puts the address pattern on the type, once, with fields in it. It declares structure in PHP classes, so the pattern is an attribute.
The pattern, on the type
#[Route('/guides/{slug}')]
#[Template('guides.page', 'guides.wide')]
class Guide extends Entry
{
#[Text(required: true, localized: true)]
public string $slug;
}
Every save writes the entry's path into a lookup table, uris, holding the site, the language, the path, and the type and id it leads to, under two unique indexes: one on the site, language and path, the other on the type, id and language, so an entry has one path in each language. A request is then one indexed read, not a query of every type's table in turn, and the per-type tables keep their real columns.
The view is the entry's own, if it chose one of those its type lists in #[Template]; otherwise the type's first; and with no #[Template] at all, the type's handle, so Article renders with resources/views/article.blade.php. A view named and missing is an error rather than a quiet step down to another one, since that would render a page with a view nobody chose.
Why a fallback route
When the routing was first decided, the catch-all was to be registered last, which would have made route order something every site had to get right. Laravel's fallback routes made that unnecessary: they are matched after every other route whatever order they were registered in, cached routes included. So Mainstay's catch-all is a fallback, and a route you write always wins.
It is not Route::fallback() itself. Laravel files every Route::fallback() under the same path, so a site's own fallback, registered after Mainstay's, would silently replace it. Mainstay's is registered under a parameter of its own and marked as a fallback, and it is the site's fallback that never runs, unless mainstay.site.enabled turns public pages off.
That has one consequence worth knowing: a route you write beats an entry at the same path without a word. Laravel's skeleton answers /up for its health check, so a page slugged up is hidden behind it. That is the escape hatch working as intended, and it is the one clash that is not refused when the entry is written, because your controller may be reading the same entry on purpose.
What is refused when it is written
A path another entry already holds. Mainstay refuses the save, on the fields that build the path, rather than appending
-2, so the editor never looks at an address they did not choose and can pick another. The unique index decides, so two saves racing for one path cannot both win.A path another language's prefix, or one of Mainstay's own routes such as the admin or the API, would answer instead, since nobody could reach it.
A slug that is not lowercase words joined by hyphens, as
Str::slug()writes them.
One address for each page
The router ignores a trailing slash, so /docs/fields/ would be a second address for /docs/fields. The catch-all redirects it to the path without one, as Laravel's own .htaccess does.
A path that leads to no entry is an ordinary 404, drawn by resources/views/errors/404.blade.php as in any Laravel application. The catch-all sets the language from the request before it looks the entry up, so the 404 is in the language of the address that was asked for.
An entry chosen as the front page is served at / in every language it has, and the page it replaces takes its own pattern's path again. Like a changed slug, choosing it changes an address every visitor uses, so it needs the publish capability for each entry it moves.