Check if a url is a known route to a next.js application ahead of time

Overview

next-known-route

Check if a url is a known route to a next.js application ahead of time.

https://www.npmjs.com/package/next-known-route

Use Case

Why do you need this? Next does not offer a way to know if a url matches a known route with the application. The only way to do it out the box is to try and preload the route, which is wasteful & only works on the client.

  • Understanding internal vs external links during render or elsewhere in your application (like utils)
  • SEO - no follow links to external sources.
  • Any feature that requires a page manifest lookup.
  • Dynamic navigation and route expressions matching.

No third party dependencies, this is all made possible by using internal parts of next router.

Usage:

In _app add the following and return it from getInitialProps

import { getRouteManifest, isKnownRoute } from 'next-known-route'

const MyApp = ()=>{
    const internalRoute = isKnownRoute('/') // or whatever path you want to check aganst. Returns true|false
    return (<main/>)
}

MyApp.getInitialProps = async (appContext) => {
    const appProps = await App.getInitialProps(appContext);

    const props = {
        ...appProps,
        knownRoutes: getRouteManifest()  // returns ['/_app','/','/[...slug]']
    };
    return props
}

Features

  • Works on server and client
  • No external libraries needed, only 50 LOC
  • getRouteManifest accepts an array of additional path expressions to match against.

Contributions are welcome.

You might also like...

Automatically document all of your Remix loaders and actions typings per each route. 📚

Automatically document all of your Remix loaders and actions typings per each route. 📚

About remix-docs-gen parses all of your Remix loaders and actions and automatically documents all the typings per each route. Installation First, you

Nov 9, 2022

End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register route handlers. LOL

Chino intelligence in japaneese End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register rou

Sep 12, 2022

API for the Baby Food Introduction Application. Keep your baby's food introductions in check with this application and backtrack in case of allergies!

API for the Baby Food Introduction Application. Keep your baby's food introductions in check with this application and backtrack in case of allergies!

Baby food introduction API This API is part of the Baby Food Introduction application, which aims to help technological parents keep track of the food

Nov 25, 2022

Allows you to build fetcher function by URL at compile-time.

Allows you to build fetcher function by URL at compile-time.

fetch.macro Allows you to build fetcher function by URL at compile-time. Usage Simply install and configure babel-plugin-macros and then use fetch.mac

Nov 7, 2022

This project entails a To-do-List whereby a user can input the tasks they want to do, check the tasks done and also clear all tasks when all of them are completed. It is efficient for a user who want to manage their time and keep track of their day.

This project entails a To-do-List whereby a user can input the tasks they want to do, check the tasks done and also clear all tasks when all of them are completed. It is efficient for a user who want to manage their time and keep track of their day.

Screenshot Here is a screenshot for the project. To-Do-List Project This is a Microverse project that entails a to-do-list which one is able to add an

Jun 16, 2022

Check your data which may be stolen every time you visit a site. ⚠️

Check your data which may be stolen every time you visit a site. ⚠️

df : Digital Fingerprint 🪄 Features Check your data which may be stolen every time you visit a site. 🌎 Geographical Data IP Address City Region Coun

Oct 17, 2022

A simple To-do app project made using JavaScript ES6 and Webpack - Microverse. You can add, remove, check tasks, and remove all the tasks that were done at the same time. Feel free to see the live version, if you like it please give it a star!

To Do List a to do list javascript app buit using webpack and es6. Built With HTML CSS JavaScript Wepack Live Demo (if available) Live Demo Link Getti

Dec 17, 2022

Another full-stack URL Shortener application built using web technologies

Another full-stack URL Shortener application built using web technologies

URL Shortener Another full-stack URL Shortener application built using web technologies. Technologies Node Express MongoDB React TypeScript Docker Pro

Dec 15, 2022

Tools to check version monitoring (updates) for web application. web 应用版本监测(更新)工具库

Tools to check version monitoring (updates) for web application. web 应用版本监测(更新)工具库

🔔 version-rocket 🚀 English | 简体中文 Notify users when a new version of your site is available and prompt them to refresh the page. When you finish dep

Dec 29, 2022
Comments
  • Configure CleanThat

    Configure CleanThat

    Welcome to CleanThat!

    This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    :vertical_traffic_light: To activate CleanThat, merge this Pull Request. To disable CleanThat, simply close this Pull Request unmerged.


    Configuration Summary

    Based on the default config's presets, CleanThat will:

    • Apply formatting over '.*.java' files

    :abcd: Would you like to change the way CleanThat is cleaning your code? Simply edit the cleanthat.json in this branch with your custom config.

    What to Expect

    PR being open to clean the default branch

    Other branches being automatically linted.


    This PR has been generated by CleanThat.


    @blacelle please consider me

    opened by cleanthat[bot] 0
Owner
Zack Jackson
Principal Engineer | Webpack maintainer, Inventor & co-creator of Module Federation, Universal Javascript, JavasScript orchestration at scale.
Zack Jackson
Compile Master CSS ahead of time with zero-configuration integration with build tools

CSS Compiler Compile Master CSS ahead of time with zero-configuration integration with build tools On this page Usage webpack.config.js vite.config.js

Master 5 Oct 31, 2022
Check in, check the weather, Check out.

☀️ Just-Weather ??️ Hi, Welcome! Just Weather is a Web App designed for Fast Real-Time Weather queries in combination with well Thought Out Visual Des

Miguel Ángel 6 Aug 7, 2022
A mobile web application to check the data on the total covid19 confirmed cases and deaths, check data for all countries with recorded cases.

This is a mobile web application to check the data on the total covid19 confirmed cases and deaths, check data for all countries with recorded cases. It also has a details page to check for the statistics for each region/state if available.

Solomon Hagan 7 Jul 30, 2022
Piccloud is a full-stack (Angular & Spring Boot) online image clipboard that lets you share images over the internet by generating a unique URL. Others can access the image via this URL.

Piccloud Piccloud is a full-stack application built with Angular & Spring Boot. It is an online image clipboard that lets you share images over the in

Olayinka Atobiloye 3 Dec 15, 2022
Modern Spatial Reference System Class. Supports EPSG Codes, PROJ4 String, and Well-Known Text.

spatial-reference-system Modern Spatial Reference System Class. supports EPSG Codes PROJ4 Strings ESRI and OGC Well-Known Text PRJ File install npm in

Daniel J. Dufour 6 Jul 22, 2022
Automaticly parses known pocket ips patch resources, scans folders or zip files for matching roms and applies the patches.

Pocket Automaton Automaticly parses known pocket ips patch resources, scans folders or zip files for matching roms and applies the patches. Usage pock

null 3 Nov 27, 2022
Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

Cuberto Reeller Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

Cuberto 41 Jan 4, 2023
To understand the history of SACCOs, a Savings and Credit cooperative otherwise known as a Sacco is a type of corporation that aims at pooling money together.

To understand the history of SACCOs, a Savings and Credit cooperative otherwise known as a Sacco is a type of corporation that aims at pooling money together. Depending on the Saccos, there are different types of supplies of merchandise. These include and are not limited to recognition servers, sedimentation, and call home eggs installation. More to these items include check glades, bankers, checks standing orders and safe detentions, and salary progress.

incredicoder 2 Oct 19, 2022
Search through all stops/stations known by Deutsche Bahn's HAFAS API.

db-stops-search Search through all stops/stations known by Deutsche Bahn's HAFAS API. Formats and imports the stops into a Meilisearch instance. Insta

Jannis R 3 Oct 4, 2022
Framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. 🗺️ Remix driver included. 🤟

About routes-gen is a framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. Think of it as Prisma,

Stratulat Alexandru 192 Jan 2, 2023