0.0.4 ā€¢ Published 2 years ago

next-last-path v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Next Last Path Hook

AKA: useLastPath

šŸ„‰ A React Hook containing the last path from a Next.js route + some goodies šŸŽ

Specially useful when working with dynamic routes

Install

npm i next-last-path

Usage

import { useLastPath } from 'uselastpath'

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

OptionTypeDescription
matcherRegExp | string | Record<string, RegExp | string>A RegExp, a string, or an Object with RegExp or strings as values. Perform a match on the lastPath
allowBracketsbooleanIf route is dynamic, allow brackets on the final result of lastPath.
allowDotsbooleanIf route is dynamic, allow dots on the final result of lastPath.
defaultHomestringBy default the homepage is returned as /. If you are in / instead defaultHome will be returned.