Skip to content

Commit 0519802

Browse files
committed
docs: Document extra property 'params'
1 parent 0882301 commit 0519802

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

README.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Dynamic Routes for Next.js
22

3-
[![npm version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=js&type=6&v=1.0.40&x2=0)](https://www.npmjs.com/package/trovit-next-routes) [![Coverage Status](https://coveralls.io/repos/github/trovit/next-routes/badge.svg)](https://coveralls.io/github/trovit/next-routes) [![Build Status](https://travis-ci.org/trovit/next-routes.svg?branch=master)](https://travis-ci.org/trovit/next-routes)
3+
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
4+
[![Coverage Status](https://coveralls.io/repos/github/trovit/next-routes/badge.svg)](https://coveralls.io/github/trovit/next-routes)
5+
[![Build Status](https://travis-ci.org/trovit/next-routes.svg?branch=master)](https://travis-ci.org/trovit/next-routes)
46

57
Easy to use universal dynamic routes for [Next.js](https://github.com/zeit/next.js)
68

79
- Express-style route and parameters matching
810
- Request handler middleware for express & co
911
- `Link` and `Router` that generate URLs by route definition
1012

13+
----
14+
> NOTE: This project was forked from [next-routes](https://github.com/fridays/next-routes) on version 1.0.40.
15+
----
16+
1117
## How to use
1218

1319
Install:
@@ -22,11 +28,12 @@ Create `routes.js` inside your project:
2228
const routes = module.exports = require('next-routes')()
2329

2430
routes
25-
.add('about')
26-
.add('blog', '/blog/:slug')
27-
.add('user', '/user/:id', 'profile')
28-
.add('/:noname/:lang(en|es)/:wow+', 'complex')
29-
.add({name: 'beta', pattern: '/v3', page: 'v3'})
31+
.add('about')
32+
.add('blog', '/blog/:slug')
33+
.add('user', '/user/:id', 'profile')
34+
.add('/:noname/:lang(en|es)/:wow+', 'complex')
35+
.add({name: 'beta', pattern: '/v3', page: 'v3'})
36+
.add({name: 'beta', pattern: '/:noname/:lang', page: 'v3', params: {type: 2}})
3037
```
3138

3239
This file is used both on the server and the client.
@@ -42,8 +49,13 @@ Arguments:
4249
- `name` - Route name
4350
- `pattern` - Route pattern (like express, see [path-to-regexp](https://github.com/pillarjs/path-to-regexp))
4451
- `page` - Page inside `./pages` to be rendered
52+
- `object` - Contains properties `name`, `pattern` and `page` in addition to `params` that is an object with extra properties that will be added to the `query` object. It can be used to set default value or to attach new properties.
53+
54+
The page component receives the matched URL parameters merged into `query`. The `query` will receive:
4555

46-
The page component receives the matched URL parameters merged into `query`
56+
- Matched properties on the pattern
57+
- Extra properties specified in the `params` object
58+
- A `routeName` property with the value of the `name` param.
4759

4860
```javascript
4961
export default class Blog extends React.Component {

0 commit comments

Comments
 (0)