{"_id":"@dsch/next-routes","_rev":"100-b2991c8d6f492ddd494243c6e73b5089","name":"@dsch/next-routes","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@dsch/next-routes","version":"2.0.0","keywords":["next","next.js","react","route","router","routes","routing"],"author":{"name":"fridays"},"license":"MIT","_id":"@dsch/next-routes@2.0.0","maintainers":[{"name":"seancull","email":"sean.culleton@distilled.ie"},{"name":"kevinmurphy","email":"kevin.murphy@distilled.ie"},{"name":"ddben","email":"ben+npmjs@donedeal.ie"},{"name":"daraclare","email":"daraclare@gmail.com"},{"name":"gdetassigny","email":"gabriel@multivac.cc"},{"name":"emurph","email":"murphe21@tcd.ie"},{"name":"cristianmoisa","email":"cristian.moisa@distilled.ie"},{"name":"distilledsch","email":"npm@distilled.ie"},{"name":"garymeehan","email":"garymeehan@outlook.com"},{"name":"seanydee","email":"demps.sean@gmail.com"},{"name":"woppers","email":"phillystafford@gmail.com"},{"name":"enda25","email":"enda.brody@distilled.ie"}],"homepage":"https://github.com/distilledmedia/next-routes#readme","bugs":{"url":"https://github.com/distilledmedia/next-routes/issues"},"dist":{"shasum":"0ae0a224f12a495d8da312e2713e025fb51151c4","tarball":"https://registry.npmjs.org/@dsch/next-routes/-/next-routes-2.0.0.tgz","fileCount":8,"integrity":"sha512-gzDBR2x+y3nupZcH9XBuIYDtPbXtU+5CPkTmzO6U0sMtlxF8M7W4OfWxNmFZ1Qgj4Bs9gsi3n9QoFzdcmZHbEw==","signatures":[{"sig":"MEQCICuoZnnquckh0yBFBc5Q6evhBXdKQjkwdy7jpXoQHtiFAiBc07l6iG3zMJDIPLcnGkiwNEoloyRDh37aokkWk0lJAg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21233,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2EjzCRA9TVsSAnZWagAAiD8P/iZwaomnz2sLcFfv9eW5\ngys9HmfzM+VIwaVJaWWLYP3aOpWMTxEFt/b0zLutsxcbm+Pm7UE9TVwfSV3N\n4oxAdsPTMHuO7HaQwUEWG6NXNe0y6TOHsxjp3S1lA/OnkmTc1dvRcQdonNvi\npovtCZFScUFsNt+zDk3j/hf+9jr4kp5u1vLA0qmPKAWUNZPbELdCDSEl3QB3\nSNhCpzKm1Edgpjh1kFnBTL8CIqDKZJjgZZv/fmA88FGuGN3yLxZsuN00kD6O\nhEKU3umxS1QdBaO4caHnXILc8Y/XhabfgpQmSGp7evzRg+dhaV1mps9NHTjF\nxdCWba7uCWSgrNyEI6wAYXksPHfhlT40LKXRA4kQhMUCU+wTcGrvU09ZVjMf\nYbU/T+7MbXDOxrCaLE5E2FmgLXyNtAXP1AcflkSUHWR8nOjCqjpDnxMHE9ki\nsuB0qd/InEyfiTrlTYxHmJIj/q4ukS83aIYmEiMXF0iAsxHIx5lTy62eiP/A\ntgFMd1z0PclzzPpRLYvkD8Y99FNpCTwfLn2zHkyuS3RNbkEWpoN5KEAQe22v\nxQ+uYUfBc5oeRrbe5m6je5p+u1IZ38V33xc/h9h0+xpYORljrl3Ji/Rjwsdg\nmlzoo25vwlQ3nuHt3ebGHqe+jnIfOBSk0IY7GG8hc/UH7Q3oYqA/1PzcYokc\nBqHs\r\n=zves\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"roots":["test/","dist/"],"testEnvironment":"node"},"main":"dist","gitHead":"6c45ccecabdc9ff2f14d89adade5d5e6dd5436c4","scripts":{"dev":"concurrently -k 'npm run build -- -w' 'npm run testOnly -- --watch'","lint":"standard 'src/*' 'test/*'","test":"npm run testOnly && npm run testTypings","build":"del dist/* && babel src -d dist","pretest":"npm run lint && npm run build","testOnly":"jest \\.test.js --coverage","testTypings":"tsc --project ./typings/tests","prepublishOnly":"npm run test"},"typings":"typings/next-routes.d.ts","_npmUser":{"name":"garymeehan","email":"garymeehan@outlook.com"},"standard":{"parser":"babel-eslint"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.","repository":{"url":"git+https://github.com/distilledmedia/next-routes.git","type":"git"},"_npmVersion":"6.4.1","description":"Easy to use universal dynamic routes for Next.js","directories":{},"_nodeVersion":"8.11.3","dependencies":{"path-to-regexp":"^2.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"23.6.0","next":"7.0.2","react":"16.6.3","del-cli":"1.1.0","standard":"12.0.1","react-dom":"16.6.3","@babel/cli":"7.2.0","babel-core":"7.0.0-bridge.0","babel-jest":"23.6.0","prop-types":"15.6.2","typescript":"3.2.2","@babel/core":"7.2.0","@types/next":"7.0.5","@types/node":"10.12.12","babel-eslint":"10.0.1","concurrently":"4.1.0","@babel/preset-env":"7.2.0","react-test-renderer":"16.6.3"},"peerDependencies":{"next":">=2","react":"^15.4.2 || ^16"},"_npmOperationalInternal":{"tmp":"tmp/next-routes_2.0.0_1545141577345_0.5062878845889078","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-12-18T13:59:37.226Z","modified":"2026-09-10T08:18:21.113Z","2.0.0":"2018-12-18T13:59:37.515Z"},"bugs":{"url":"https://github.com/distilledmedia/next-routes/issues"},"author":{"name":"fridays"},"license":"MIT","homepage":"https://github.com/distilledmedia/next-routes#readme","keywords":["next","next.js","react","route","router","routes","routing"],"repository":{"url":"git+https://github.com/distilledmedia/next-routes.git","type":"git"},"description":"Easy to use universal dynamic routes for Next.js","maintainers":[{"email":"xi.jiang@distilled.ie","name":"ruby_jiang"},{"email":"zara.kinneen@distilled.ie","name":"zarakinneen"},{"email":"jayoe08@gmail.com","name":"jastew"},{"email":"andredistilledgithub@gmail.com","name":"andremacnamara"},{"email":"brian.kinsella@distilled.ie","name":"briankinsella26"},{"email":"steven.kirwan@distilled.ie","name":"steven-kirwan"},{"email":"jady.martins@distilled.ie","name":"distilledjady"},{"email":"corey.clancy@distilled.ie","name":"coreyclancy"},{"email":"edel.prior@distilled.ie","name":"prioredel"},{"email":"cristian.moisa@distilled.ie","name":"cristianmoisa"},{"email":"stephen.finegan@distilled.ie","name":"stephenfdistilled"},{"email":"shane.lilly@distilled.ie","name":"shane.lilly"},{"email":"patrick.duffy@distilled.ie","name":"patrick.duffy"},{"email":"colum.foskin@distilled.ie","name":"cfoskindistilled"},{"email":"ros.corcoran@distilled.ie","name":"rosccc"},{"email":"mohamed.abad@distilled.ie","name":"mohamed.abad"},{"email":"hugh.odonoghue@distilled.ie","name":"hughatdistilled"},{"email":"tanner.lyons@distilled.ie","name":"tannerlyons-distilled"},{"email":"sean.culleton@distilled.ie","name":"seancull"},{"email":"mayukh.sengupta@distilled.ie","name":"mayukh.sengupta"},{"email":"joe.obrien@distilled.ie","name":"joe-obrien"},{"email":"stephen.byrne@distilled.ie","name":"stephen_byrne"},{"email":"iain.mchugh@distilled.ie","name":"iaindev"},{"email":"abdelghafo@gmail.com","name":"ennahid1"},{"email":"ronan.doyle@distilled.ie","name":"ronan-distilled"},{"email":"anton.skavronskij@distilled.ie","name":"skavronskijadistilled"},{"email":"mahdi.berriri@distilled.ie","name":"mahdiberriri"},{"email":"tom.pradat@distilled.ie","name":"distilledtom"},{"email":"bryan.dennehy@distilled.ie","name":"bryan.dennehy"},{"email":"bogdan.filimon@distilled.ie","name":"bogdanfilimon"},{"email":"brian.murphy@distilled.ie","name":"brianmurphy-distilled"},{"email":"jason.blood@distilled.ie","name":"jason.blood"},{"email":"pooria.tazik@distilled.ie","name":"ptazik"}],"readme":"# Dynamic Routes for Next.js\n\n**NOTICE: This is a fork of [Yolk-HQ/next-routes](https://github.com/Yolk-HQ/next-routes). This fork contains a fix for array parameter handling:\n\nNextJS will convert an array to url params in this manner:\n```\nRouter.push({\n      pathname: '/path',\n      query: { queryArray: [1, 2, 3] },\n    });\n```\n=>\n`/path&queryArray=1&queryArray=2&queryArray=3`\n\nprevious forks of next-routes will do the following:\n`/path&queryArray=1%2F2%2F3`\n\nThis Fork makes this behaviour consistent, and will do the same as NextJS (i.e: `/path&queryArray=1&queryArray=2&queryArray=3`)\n\nEasy to use universal dynamic routes for [Next.js](https://github.com/zeit/next.js)\n\n- Express-style route and parameters matching\n- Request handler middleware for express & co\n- `Link` and `Router` that generate URLs by route definition\n\n## How to use\n\nInstall:\n\n```bash\nnpm install @dsch/next-routes --save\n```\n\nCreate `routes.js` inside your project:\n\n```javascript\nconst routes = require('@dsch/next-routes')\n\n                                                    // Name   Page      Pattern\nmodule.exports = routes()                           // ----   ----      -----\n.add('about')                                       // about  about     /about\n.add('blog', '/blog/:slug')                         // blog   blog      /blog/:slug\n.add('user', '/user/:id', 'profile')                // user   profile   /user/:id\n.add('/:noname/:lang(en|es)/:wow+', 'complex')      // (none) complex   /:noname/:lang(en|es)/:wow+\n.add({name: 'beta', pattern: '/v3', page: 'v3'})    // beta   v3        /v3\n```\n\nThis file is used both on the server and the client.\n\nAPI:\n\n- `routes.add([name], pattern = /name, page = name)`\n- `routes.add(object)`\n\nArguments:\n\n- `name` - Route name\n- `pattern` - Route pattern (like express, see [path-to-regexp](https://github.com/pillarjs/path-to-regexp))\n- `page` - Page inside `./pages` to be rendered\n\nThe page component receives the matched URL parameters merged into `query`\n\n```javascript\nexport default class Blog extends React.Component {\n  static async getInitialProps ({query}) {\n    // query.slug\n  }\n  render () {\n    // this.props.url.query.slug\n  }\n}\n```\n\n## On the server\n\n```javascript\n// server.js\nconst next = require('next')\nconst routes = require('./routes')\nconst app = next({dev: process.env.NODE_ENV !== 'production'})\nconst handler = routes.getRequestHandler(app)\n\n// With express\nconst express = require('express')\napp.prepare().then(() => {\n  express().use(handler).listen(3000)\n})\n\n// Without express\nconst {createServer} = require('http')\napp.prepare().then(() => {\n  createServer(handler).listen(3000)\n})\n```\n\nOptionally you can pass a custom handler, for example:\n\n```javascript\nconst handler = routes.getRequestHandler(app, ({req, res, route, query}) => {\n  app.render(req, res, route.page, query)\n})\n```\n\nMake sure to use `server.js` in your `package.json` scripts:\n\n```json\n\"scripts\": {\n  \"dev\": \"node server.js\",\n  \"build\": \"next build\",\n  \"start\": \"NODE_ENV=production node server.js\"\n}\n```\n\n## On the client\n\nImport `Link` and `Router` from your `routes.js` file to generate URLs based on route definition:\n\n### `Link` example\n\n```jsx\n// pages/index.js\nimport {Link} from '../routes'\n\nexport default () => (\n  <div>\n    <div>Welcome to Next.js!</div>\n    <Link route='blog' params={{slug: 'hello-world'}}>\n      <a>Hello world</a>\n    </Link>\n    or\n    <Link route='/blog/hello-world'>\n      <a>Hello world</a>\n    </Link>\n  </div>\n)\n```\n\nAPI:\n\n- `<Link route='name'>...</Link>`\n- `<Link route='name' params={params}> ... </Link>`\n- `<Link route='/path/to/match'> ... </Link>`\n\nProps:\n\n- `route` - Route name or URL to match (alias: `to`)\n- `params` - Optional parameters for named routes\n\nIt generates the URLs for `href` and `as` and renders `next/link`. Other props like `prefetch` will work as well.\n\n### `Router` example\n\n```jsx\n// pages/blog.js\nimport React from 'react'\nimport {Router} from '../routes'\n\nexport default class Blog extends React.Component {\n  handleClick () {\n    // With route name and params\n    Router.pushRoute('blog', {slug: 'hello-world'})\n    // With route URL\n    Router.pushRoute('/blog/hello-world')\n  }\n  render () {\n    return (\n      <div>\n        <div>{this.props.url.query.slug}</div>\n        <button onClick={this.handleClick}>Home</button>\n      </div>\n    )\n  }\n}\n```\n\nAPI:\n\n- `Router.pushRoute(route)`\n- `Router.pushRoute(route, params)`\n- `Router.pushRoute(route, params, options)`\n\nArguments:\n\n- `route` - Route name or URL to match\n- `params` - Optional parameters for named routes\n- `options` - Passed to Next.js\n\nThe same works with `.replaceRoute()` and `.prefetchRoute()`\n\nIt generates the URLs and calls `next/router`\n\n---\n\nOptionally you can provide custom `Link` and `Router` objects, for example:\n\n```javascript\nconst routes = module.exports = require('@dsch/next-routes')({\n  Link: require('./my/link')\n  Router: require('./my/router')\n})\n```\n\n---\n\n##### Related links\n\n- [zeit/next.js](https://github.com/zeit/next.js) - Framework for server-rendered React applications\n- [path-to-regexp](https://github.com/pillarjs/path-to-regexp) - Express-style path to regexp\n","readmeFilename":"README.md"}