1.0.3 • Published 1 year ago

breadcrumbs-next v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Breadcrumbs for NextJS

Table of contents

Installation

npm install breadcrumbs-next
yarn install breadcrumbs-next
pnpm install breadcrumbs-next

Behind The Scenes

Imagine your app having the following routes: 1. /momentum 2. /projects/[projectId] 3. /[[…slug]] 4. /users/[userId]/[[…stuff]] 5. /users/[userId]/[[…slug]]?t=record 6. /users?t=record 7. /users/[userId]?t=record

Last three examples also include URL parameters, which can be used to construct breadcrumbs. For example, when you have a page consisting from another set of tabs, but you don't want to create another route for that.

All of those examples can be transformed to the following formats (lets omit Home element in resulting breadcrumbs):

PatternBreadcrumbsExample URL
/momentumMomentum=
/profile?t=recordsProfile > Records=
/projects/[projectId]Projects > "Grammar"/projects/17
/[[…slug]]Russia > Moscow > Subway > Kommunarka/russia/moscow/subway/kommunarka
/users/[userId]/[[…stuff]]Users > Pavel > Deliveries > Yandex > Lavka/users/132/deliveries/yandex/lavka
/users/[userId]/[[…slug]]?t=records1Users > Pavel > Deliveries > Dashboard > Record/users/132/deliveries/dashboard?t=records
/users/[userId]?t=recordsUsers > Pavel > Records/users/132?t=records

1 - Search params always are taken last, because change of URL (w/o params) is the same as opening another page, thus even having the same params set int the URL doesn't mean they should go in the beginning. They are behaviour modifiers of the page, but not its primary descriptor.

Contents

Type Aliases

Components

Functions

Type Aliases

BreadCrumb

Type declaration

NameType
hrefstring
textstring
textGeneratornull or TextGeneratorFn

CrumbComponentProps

Type Declaration

NameType
hrefstring
isFirstboolean
isLastboolean
textstring
textGeneratornull or TextGeneratorFn

GetDefaultTextGenerator

Type declaration

▸ (config) => string

Parameters
NameType
configObject
config.hrefstring
config.isCatchAllSubpathboolean
config.paramIndexnumber
config.paramNamestring
config.isCatchAllSubpathboolean
config.paramSlugIndexnull or number
config.paramValuestring
config.queryNextRouter"query"

GetTextGenerator

Type declaration

▸ (config) => null | TextGeneratorFn

Parameters
NameType
configObject
config.hrefstring
config.isCatchAllSubpathboolean
config.paramIndexnumber
config.paramNamestring
config.paramSlugIndexnull or number
config.paramValuestring
config.queryNextRouter"query"

NextBreadcrumbsProps

Type declaration

NameType
Containerstring or FC<{children: ReactNode}>
CrumbFC<CrumbComponentProps>
getDefaultTextGenerator?GetDefaultTextGenerator
getTextGenerator?GetTextGenerator
homeText?string

Used in:


TextGeneratorFn

Type declaration

▸ () => string | Promise<string>

Used in:

Components

NextBreadcrumbs

Props

NameType
{...props}NextBreadcrumbsProps

Functions

createNextCrumbComponent

Parameters

NameType
ComponentFC<Omit<CrumbComponentProps, "textGenerator">>

Returns

FC<CrumbComponentProps>

Testing

yarn install-peers
yarn vitest

TODOs

  • add support for query params to be items of breadcrumbs
  • add all required tests
1.0.2

1 year ago

1.0.1

1 year ago

1.0.3

1 year ago

1.0.0

1 year ago

1.0.0-alpha.4

1 year ago

1.0.0-alpha.3

1 year ago

1.0.0-alpha.2

1 year ago

1.0.0-alpha.1

1 year ago

1.0.0-alpha.0

1 year ago