
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
@dsch/next-routes
Advanced tools
**NOTICE: This is a fork of Yolk-HQ/next-routes. This fork contains a fix for array parameter handling:
NextJS will convert an array to url params in this manner:
Router.push({
pathname: '/path',
query: { queryArray: [1, 2, 3] },
});
=>
/path&queryArray=1&queryArray=2&queryArray=3
previous forks of next-routes will do the following:
/path&queryArray=1%2F2%2F3
This Fork makes this behaviour consistent, and will do the same as NextJS (i.e: /path&queryArray=1&queryArray=2&queryArray=3
)
Easy to use universal dynamic routes for Next.js
Link
and Router
that generate URLs by route definitionInstall:
npm install @dsch/next-routes --save
Create routes.js
inside your project:
const routes = require('@dsch/next-routes')
// Name Page Pattern
module.exports = routes() // ---- ---- -----
.add('about') // about about /about
.add('blog', '/blog/:slug') // blog blog /blog/:slug
.add('user', '/user/:id', 'profile') // user profile /user/:id
.add('/:noname/:lang(en|es)/:wow+', 'complex') // (none) complex /:noname/:lang(en|es)/:wow+
.add({name: 'beta', pattern: '/v3', page: 'v3'}) // beta v3 /v3
This file is used both on the server and the client.
API:
routes.add([name], pattern = /name, page = name)
routes.add(object)
Arguments:
name
- Route namepattern
- Route pattern (like express, see path-to-regexp)page
- Page inside ./pages
to be renderedThe page component receives the matched URL parameters merged into query
export default class Blog extends React.Component {
static async getInitialProps ({query}) {
// query.slug
}
render () {
// this.props.url.query.slug
}
}
// 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
const express = require('express')
app.prepare().then(() => {
express().use(handler).listen(3000)
})
// Without express
const {createServer} = require('http')
app.prepare().then(() => {
createServer(handler).listen(3000)
})
Optionally you can pass a custom handler, for example:
const handler = routes.getRequestHandler(app, ({req, res, route, query}) => {
app.render(req, res, route.page, query)
})
Make sure to use server.js
in your package.json
scripts:
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
}
Import Link
and Router
from your routes.js
file to generate URLs based on route definition:
Link
example// pages/index.js
import {Link} from '../routes'
export default () => (
<div>
<div>Welcome to Next.js!</div>
<Link route='blog' params={{slug: 'hello-world'}}>
<a>Hello world</a>
</Link>
or
<Link route='/blog/hello-world'>
<a>Hello world</a>
</Link>
</div>
)
API:
<Link route='name'>...</Link>
<Link route='name' params={params}> ... </Link>
<Link route='/path/to/match'> ... </Link>
Props:
route
- Route name or URL to match (alias: to
)params
- Optional parameters for named routesIt generates the URLs for href
and as
and renders next/link
. Other props like prefetch
will work as well.
Router
example// pages/blog.js
import React from 'react'
import {Router} from '../routes'
export default class Blog extends React.Component {
handleClick () {
// With route name and params
Router.pushRoute('blog', {slug: 'hello-world'})
// With route URL
Router.pushRoute('/blog/hello-world')
}
render () {
return (
<div>
<div>{this.props.url.query.slug}</div>
<button onClick={this.handleClick}>Home</button>
</div>
)
}
}
API:
Router.pushRoute(route)
Router.pushRoute(route, params)
Router.pushRoute(route, params, options)
Arguments:
route
- Route name or URL to matchparams
- Optional parameters for named routesoptions
- Passed to Next.jsThe same works with .replaceRoute()
and .prefetchRoute()
It generates the URLs and calls next/router
Optionally you can provide custom Link
and Router
objects, for example:
const routes = module.exports = require('@dsch/next-routes')({
Link: require('./my/link')
Router: require('./my/router')
})
FAQs
Easy to use universal dynamic routes for Next.js
The npm package @dsch/next-routes receives a total of 0 weekly downloads. As such, @dsch/next-routes popularity was classified as not popular.
We found that @dsch/next-routes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.