@weresk/router
v0.1.2
Published
**@weresk/router** Toolkit for working with links in Next.js app
Downloads
66
Readme
@weresk/router Toolkit for working with links in Next.js app
Exports
Types
- Schemas
linkTyped({router: RouterConfig, localization?: LocalizationConfig}): Link with manual selection between link types: reference, anchor, external, internal or filelinkExternal({router: RouterConfig, localization?: LocalizationConfig}): Link with a caption and external URLlinkCaptioned({router: RouterConfig, localization?: LocalizationConfig}): Link with a caption and typed linklinkContact({router: RouterConfig, localization?: LocalizationConfig}): Typed contact linknormalizedSlug({router: RouterConfig, localization?: LocalizationConfig}): Slug schema with slugify and isUnique functions setrouterObjects({router: RouterConfig, localization?: LocalizationConfig}): Generates an array of schema definitions with all types listed above
Types
- Props
ReferenceDocument: Base Sanity document type with title, slug and optional parentRouterSchemaProps: Props for router schemas definitionRouterConfig<DocumentType extends ReferenceDocument = ReferenceDocument>: Router config objectmode: "parent" | "folder": Defines what strategy is used for pages structure:parent: Documents are nested under the parent document like/parents-parent/parent/slugfolder: Documents are grouped inside the folder determined by document type, usingroutesconfiguration, like/folder/slug
schemas: string[]: Link of document schemas that can be referenced in linksroutes: Record<DocumentType["_type"], string>: Object with document types as keys and folder names as values to use infoldermodecontacts?: ContactType[]: Optional customization of contacts types forlinkContactschemaparentDepth?: number: Optional customization of nesting depth limit used inparentmode
Contants
contactTypeList: List of contact types
Utils
getDocumentPath(doc: ReferenceDocument | undefined, config: RouterConfig): string: Generates URL for a documentgetLinkType(url: string): LinkType: Checks the link type for a URLgetTypesWithSameRoute(docType: string | undefined, routes: Record<string, string>): string[]: Finds the documents types that have the route similar to a singular document typeisUniqueSlugFunction(config: RouterConfig): (slug: string, context: SlugValidationContext) => Promise<boolean>: Generates isUniqueSlug function based on router confignormalizeLink(input: string): string: Normalizes a string to be used as a URLprepareLink(input: LinkTyped, router: RouterConfig, lang?: IsoLocale): string: Generates an URL from aLinkTypedobjecttoLinkCaptioned<Reference extends ReferenceDocument = ReferenceDocument>(doc: Reference): LinkCaptioned<NonNullable<Reference["title"]>, LinkTyped<Reference>>: Converts a document type intoLinkCaptionedwrapReference(doc: ReferenceDocument): LinkTyped: Converts a document type intoLinkTyped
Components
LinkWrapper: A wrapper function to render a Next.js link from router schemas like typed link, reference and href- Props:
LinkWrapperProps extends LocaleProps<DefaultPropsWithChildren>href?: string: URL, is set used firstreference?: ReferenceDocument: Refefence to a document, if set used before thelinklink?: LinkTyped: Typed linktitle?: string:titleproperty for rendered HTML elementconfig: RouterConfig: Router configuration
- Props:
ContactLink: Renders contact link as a text or as an icon- Props:
ContactLinkProps extends LocaleProps<DefaultProps>link: LinkContact: Contact type identifiermode: "text" | "icon": Render modeconfig: RouterConfig: Router configuration
- Props:
