Waku provides a router built on top of the minimal API, and it serves as a reference implementation. While other router implementations can be used with Waku, this page focuses on the waku/router
implementation.
Client API
To use the router, it is required to use the Router
component instead of using serve
directly. The following code demonstrates how to use the Router
component as the root component:
The Router
component internally uses serve
and handles nested routes.
Server API
In entries.ts
, we use defineRouter
to export getEntry
and getBuildConfig
at once. Here's a simple example code without builder:
The implementation of the defineRouter
is config-based. However, it isn't too difficult to make a file-based router. Here's a file-based example code with builder:
Due to the limitation of bundler, we cannot automatically allow infinite depth of routes.
How to try it
You can try an example app in the repository by cloning it and running the following commands:
Alternatively, you could create a project with something like npm create waku@latest
and copy files from the example folder in the repository.