Routing
Overview of how to define the URL of your pages.
Filesystem Routing
Vike supports Filesystem Routing: the URL of a page is determined by where the page is located on your filesystem.
The directories pages/
and index/
are ignored by Filesystem Routing.
+
files are explained at API > Config Files > +
files.
For detailed information about Filesystem Routing, see API > Filesystem Routing.
Parameterized routes
The parameter id
is available at pageContext.routeParams.id
.
Groups
You can organize your pages into groups:
Any directory inside parentheses such as (marketing)
is ignored by Filesystem Routing.
It also enables you to easily set different configurations for different pages:
See API > Config Files > Inheritance.
src/
If you prefer, you can define your files within a src/
directory:
The directory src/
is ignored by Filesystem Routing.
The directory src/
isn't ignored by config inheritance: make sure to define all your +
files inside src/
.
Domain-driven file structure
For advanced apps, you may want to consider a domain-driven file structure.
If you aren't familiar with file structures, see File Structure.
Route String
Instead of Filesystem Routing, you can define a Route String.
The parameter id
is available at pageContext.routeParams.id
.
More information at:
Route Function
You can use Route Functions to get full programmatic flexibility for advanced routing logic.
More information at:
Route Guards
You can use a guard()
hook to protect pages from unauthorized/unexpected access.
This guard()
hook applies to all pages living at /pages/admin/**/*
, see API > Config Files > Inheritance.
More information at:
React Router / Vue Router
Although we usually don't recommend it, you can use Vike with React Router and Vue Router:
See also