# next-routes **Repository Path**: mirrors_jaydenseric/next-routes ## Basic Information - **Project Name**: next-routes - **Description**: Universal named routes for next.js - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-09 - **Last Updated**: 2026-09-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Named routes for next.js [](https://travis-ci.org/fridays/next-routes) [](https://www.npmjs.com/package/next-routes) [](https://greenkeeper.io/) Easy to use universal named routes for [next.js](https://github.com/zeit/next.js) - Express-style route and parameters matching - Request handler middleware for express & co - `Link` and `Router` that generate URLs by route name ## How to use Install: ```bash npm install next-routes ``` Create `routes.js` inside your project root: ```javascript // routes.js const nextRoutes = require('next-routes') const routes = module.exports = nextRoutes() routes.add('blog', '/blog/:slug') routes.add('about', '/about-us/:foo(bar|baz)', 'index') ``` This file is used both on the server and the client. API: `routes.add(name, pattern, page = name)` - `name` - The route name - `pattern` - Express-style route pattern (uses [path-to-regexp](https://github.com/pillarjs/path-to-regexp)) - `page` - Page inside `./pages` to be rendered (defaults to `name`) The page component receives the matched URL parameters merged into `query` ```javascript export default class Blog extends React.Component { static async getInitialProps ({query}) { // query.slug } render () { // this.props.url.query.slug } } ``` ### On the server ```javascript // server.js const next = require('next') const routes = require('./routes') const app = next({dev: process.env.NODE_ENV !== 'production'}) const handler = routes.getRequestHandler(app) // With express.js const express = require('express') app.prepare().then(() => { express().use(handler).listen(3000) }) // Without express.js const {createServer} = require('http') app.prepare().then(() => { createServer(handler).listen(3000) }) ``` ### On the client Thin wrappers around `Link` and `Router` add support for generated URLs based on route name and parameters. Just import them from your `routes` file: #### `Link` example ```jsx // pages/index.js import {Link} from '../routes' export default () => (