UNPKG

@tanstack/react-router

Version:

Modern and scalable routing for React applications

1 lines 1.19 kB
{"version":3,"file":"useRouter.cjs","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { getRouterContext } from './routerContext'\nimport type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'\n\n/**\n * Access the current TanStack Router instance from React context.\n * Must be used within a `RouterProvider`.\n *\n * Options:\n * - `warn`: Log a warning if no router context is found (default: true).\n *\n * @returns The registered router instance.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook\n */\nexport function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {\n warn?: boolean\n}): TRouter {\n const value = React.useContext(getRouterContext())\n warning(\n !((opts?.warn ?? true) && !value),\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":["React","getRouterContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeO,SAAS,UAAwD,MAE5D;AACV,QAAM,QAAQA,iBAAM,WAAWC,cAAAA,iBAAA,CAAkB;AACjD;AAAA,IACE,GAAG,MAAM,QAAQ,SAAS,CAAC;AAAA,IAC3B;AAAA,EAAA;AAEF,SAAO;AACT;;"}