Next router config
Path-to-regexp based custom routers for a Next.js apps.
Install
// yarnyarn add next-router-config // npmnpm i --save next-router-config
Base example
Create Routes
- Create routes config
// src/routes/config.ts; ;
RouteConfig params:
name
- route namepage
- the path of the page in/pages
pattern
- path-to-regexp pattern
- Create custom routes instance
// src/routes/index.ts;; ;
On the server
// src/server/index.ts;; ;; ; ;; ; app.prepare.then;
On the client
;; ; ; ;
API reference
Routes
-
matchUrl(url: string) => RouteMatch | undefined
RouteMatch
params
- parsed params from urlpage
- path of the page in/pages
name
- route namepattern
- path-to-regexp pattern
-
getRoute({ routeName, routeParams }) => RouteLink | undefined
RouteLink
pathname
- uripage
- path of the page in/pages
params
- route params