Statically prevent 404s in your Next.js applications using TypeScript

Overview

next-static-paths

Statically prevent HTTP 404 Not Found in your Next.js applications using TypeScript and code generation.

Features

πŸ’» A command-line interface to generate static types and custom route helper functions

πŸ”— A <TypedLink /> component which wraps Next.js <Link /> and provides type-safe path matching

πŸ“ A urlFor helper that enables path generation in a type-safe manner

Usage

$ pnpm add next-static-paths
# or
$ yarn add next-static-paths
# or
$ npm install next-static-paths

Then, from within your Next.js application root, run the following command:

# For pnpm users
$ pnpx next-static-paths

# For yarn users
$ yarn next-static-paths

# For npm users
$ npx next-static-paths

Usage screenshots

Path autocomplete

Path autocomplete

Dynamic path segment type checking

dynamic path segment type checking

Comments
  • Version Packages

    Version Packages

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Patch Changes

    • d81f4ff: add a readme to the npm package
    opened by github-actions[bot] 0
  • Version Packages

    Version Packages

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or setup this action to publish automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Patch Changes

    • 477976c: Add repository to package.json
    opened by github-actions[bot] 0
  • Version Packages

    Version Packages

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or setup this action to publish automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Patch Changes

    • 238a159: Allow TypedLink to receive children in the types
    opened by github-actions[bot] 0
  • cli: sort generated paths

    cli: sort generated paths

    This PR sort generated routes. I run the build command and test it with the example app.

    image

    Notice:

    I could extract a function that creates the routes map so I won't have to use the sortedRoutes variable and I could just call it routes, but I'm not sure what is the code style in this repo - so feel free to comment and I will fix it as you want :)

    Closes #11

    opened by nirtamir2 2
  • Sort generated Paths to avoid git diff when running `next-static-paths`

    Sort generated Paths to avoid git diff when running `next-static-paths`

    I add as a pre-commit hook to files in pages the next-static-paths script to generate the static-paths.d.ts. I notice that sometimes it creates useless git diff in static-paths.d.ts that is the same as before but with a different paths order.

    Diggin into the code I found it uses globby inside. As referenced here https://github.com/sindresorhus/globby/issues/131#issuecomment-513565156 the globby results are not deterministic. I think this causes the git diff.

    Can we sort the results to avoid this useless diff?

    We can use globbySync and run manual sort after it instead of globbyStream https://github.com/Schniz/next-static-paths/blob/main/packages/next-static-paths/cli/command-generate.ts#L105 here but it can hurt performance a bit

    Thanks!

    bug 
    opened by nirtamir2 2
  • newNextLinkBehavior - omit dynamic route props to avoid passing props to the DOM

    newNextLinkBehavior - omit dynamic route props to avoid passing props to the DOM

    Hi Thank you for creating this package!

    I have an issue that react warns me about props passing into the DOM elements when I have the newNextLinkBehavior and the children are DOM elements, and the route requires param.

    How to reproduce

    • Go to the example app
    • Upgrade deps
    • Replace the link in index.tsx to be
    <TypedLink as={"/dynamic/[userId]"} userId={"myUserId"}>
            Test
          </TypedLink>
    
    • Upgrading to the new route behavior in next.config.js
    module.exports = {
      reactStrictMode: true,
      experimental: {
        newNextLinkBehavior: true,
      },
    };
    
    • Run pnpm dev
    • Navigate to the index page in app

    Expected behavior

    TypedLink works without warning and the props do not pass to the Link component. The library omits dynamically the props passed to TypedLink like the as prop

    Actual behavior

    We get a warning

    Warning: React does not recognize the `userId` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `userid` instead. If you accidentally passed it from a parent component, remove it from the DOM element.
    

    Workaround

    We can still use the pathFor that returns a string and use the regular Link from next/link

    bug 
    opened by nirtamir2 0
Convert your SVG file directly to Flutter paths and prevent all the messing with bezier curves.

svg-to-flutter-path-converter Convert your SVG file directly to Flutter paths and prevent all the messing with bezier curves. Flutter Clutter The tool

null 30 Jan 2, 2023
Node.js package with a customized HTTP and HTTPS agents to prevent SSRF with hosts validations and custom DNS feature.

http-agent-dns This is a Node.js package with a customized HTTP and HTTPS agents to prevent SSRF with hosts validations with a possibility to use a cu

Bruno Germano 4 Jul 21, 2022
Make text fit container, prevent overflow and underflow.

AutoTextSize Make text fit container, prevent overflow and underflow. The font size of the text is adjusted so that it precisely fills its container.

Sana Labs 10 Dec 30, 2022
πŸ’» A simple Create Next App template to start your projects with Next.js, TypeScript, ESLint, Prettier and other tools.

⚑ Next Typescript Template ⚑ A simple Create Next App template to start your projects with Next.js, TypeScript, ESLint, Prettier and other tools. Quic

JoΓ£o Gabriel 13 Nov 23, 2022
A collection of Aurelia 2 example applications showcasing how to build Aurelia 2 applications and other tasks.

Aurelia 2 Examples A monorepository of a treasure trove of Aurelia 2 example applications you can use as a guide to help you build your own applicatio

aurelia 12 Dec 29, 2022
An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

Snyk Labs 57 Dec 28, 2022
This project is a boilerplate for Next and TypeScript projects. This template was built with Vite, TypeScript and Stitches.

Awesome Template Stitches β€” NextJS, TypeScript, Stitches and Design Tokens Summary About this template Avaliale scripts Other scripts available Main t

Diego Silva 14 Dec 29, 2022
next-graphql-server is a library for building production-grade GraphQL servers using Next.js with API Routes

next-graphql-server next-graphql-server is an easy to use Next.js library for creating performant GraphQL endpoints on top of Next.js API Routes. Star

Jakub Neander 82 Nov 21, 2022
A next-gen framework for type-safe command-line applications

Zors ?? Next-gen framework for building modern, type-safe command-line applications. ?? Tiny (zero dependencies) ?? Runtime agonistic (supports both D

Sidharth Rathi 13 Dec 1, 2022
Decentralized twitter using Solidity, Ethereum, hardhat, ethers, IPFS, Next.JS, TypeScript, TailwindCSS.

DWITTER: Decentralized Twitter Check out the deployed version of this app at https://dwtr.wajeshubham.in Transactions on Ethereum are slow. Therefore,

Shubham Waje 12 Sep 2, 2022
⚑ Personal website and blog made using TypeScript, Next.js, Tailwind CSS.

小康 blog View Demo · Report Bug · Request Feature ?? honghong.me Framework: Next.js Database: Planetscale ORM: Prisma Authentication: NextAuth.js Deplo

小康 94 Dec 31, 2022
Learn Web 2.0 and Web 3.0 Development using Next.js, Typescript, AWS CDK, AWS Serverless, Ethereum and AWS Aurora Serverless

Learn Web 2.0 Cloud and Web 3.0 Development in Baby Steps In this course repo we will learn Web 2.0 cloud development using the latest state of the ar

Panacloud Multi-Cloud Internet-Scale Modern Global Apps 89 Jan 3, 2023
My personal website – Built using Next.js, TypeScript, MDX, Sanity.io and Tailwind

kenaqshal.com Framework: Next.js Database: PlanetScale ORM: Prisma Authentication: NextAuth.js Deployment: Vercel CMS: Sanity Styling: Tailwind CSS Ov

Ken Aqshal Bramasta 6 Nov 24, 2022
πŸ’‘ A FullStack Quiz web app using TypeScript and Next.js!

A FullStack Quiz app using TypeScript and Next.js! This projects is in portuguese! Self Hosting npm i && npm run build && npm run start # or yarn && y

Jon4s_ 6 Aug 13, 2022
πŸ’» Template using Next + TypeScript

Hi there! ?? This project was developed with care and in the best way I could with the knowledge I have, I hope you enjoy it! ?? What is inside? Next

Giovanna Souza 14 Dec 30, 2022
Node-cli-starter - Basic starter kit for building Node CLI applications with TypeScript.

node-cli-starter Minimal starter kit for building Node CLI applications with TypeScript. Getting Started To get started clone repo locally and run npm

Cory Rylan 7 May 17, 2022
Tutorial building UI5 applications with TypeScript.

ui5-typescript-tutorial - Learn App Development in UI5 and TypeScript Overview This brief (~1-2-hours) tutorial introduces developers to UI5 applicati

SAP Samples 30 Nov 21, 2022
Toolkit for building scalable web applications with TypeScript, React, Redux and Apollo-Client

TsToolbox Toolkit for building scalable web applications with TypeScript, React, Redux and Apollo-Client (inspired by ReKit) ⚠ ⚠ ⚠ Work in Progress ⚠

Daniel Nikravesh 7 Apr 14, 2022
SEE-EYE is a collection of useful Github actions and workflows used to build CI pipelines for TypeScript applications

SEA-EYE ?? No frils collection of common actions and pre-made workflows for TypeScript project that uses yarn@v1 as package manager. Workflows Build -

Tino Thamjarat 10 Jun 6, 2022