Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
/ next-last-path Public archive

πŸ₯‰ A React Hook containing the last path from a Next.js route + some goodies 🎁

License

Notifications You must be signed in to change notification settings

lifespikes/next-last-path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

next-last-path-logo

Next Last Path Hook

AKA: useLastPath

πŸ₯‰ A React Hook containing the last path from a Next.js route + some goodies 🎁

Features

  • ⚑️ Fast
  • 🧩 Small (1.1kB gzipped).
  • πŸ₯Ά Dependency free.
  • πŸ§ͺ Based on regex.
  • 🧨 Specially useful when working with dynamic routes.

Install

npm i next-last-path

Usage

import { useLastPath } from 'next-last-path'

const Component = (props: any) => {
  const { lastPath, isLastPath, isDynamic, query, isMatch } = useLastPath()

  return <div>
    the last path is: {lastPath} {isDynamic && `and it's dynamic`}
  </div>
}

export default Component

Options

Option Type Description
matcher RegExp | string | Record<string, RegExp | string> A RegExp, a string, or an Object with RegExp or strings as values. Perform a match on the lastPath
allowBrackets boolean If route is dynamic, allow brackets on the final result of lastPath.
allowDots boolean If route is dynamic, allow dots on the final result of lastPath.
defaultHome string By default the homepage is returned as /. If you are in / instead defaultHome will be returned.

About

πŸ₯‰ A React Hook containing the last path from a Next.js route + some goodies 🎁

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published