New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nx/next-router

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nx/next-router

A routing library for Next.js

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-75%
Maintainers
2
Weekly downloads
 
Created
Source

next-router

A routing library for Next.js

NPM

Installation

npm install @nx/next-router

Introduction

This library is inspired by and works very similar than next-routes. It works with a custom server or with Next.js 9 file system routing.

Differences:
  • Build with TypeScript
  • Route configuration is provided as Object
  • Url Hashes support

How to

Define the routes

Create a file like routes.config.(ts|js) and paste the following:

import { Router, Routes, Link } from '@nx/next-router';

const routes: Routes = {
  'user': {
    pattern: '/user',
    page: '/user',
  },
  'home': {
    pattern: '/',
    page: '/index',
  }
};

const router = new Router(routes);
const link = Link(router);

export { router as Router };
export { link as Link };

We look at one root defininion:

'user': { // This is the route name
  pattern: '/user', // This is the url pattern to call the page
  page: '/user', // This is the next page (pages/user.js or pages/user/index.js)
},

The pattern can be anything that path-to-regexp understands. So a route with an optional parameter would be /user/:name? for example. path-to-regexp by the way is the same library that express is using for the routing.

Usage

You can use the exported Link component instead of the next/link.


// /user pattern
<Link route="user">
  <a>Got to User page</a>
</Link>

// /user/:name pattern
<Link route="user" params={{ name: 'stefan' }}>
  <a>Got to User detail page</a>
</Link>

FAQs

Package last updated on 20 Sep 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc