{"_id":"@akshar-technosoft/router","_rev":"3-16c82e71cf6a4fa3e3cccf33a8b8aca8","name":"@akshar-technosoft/router","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@akshar-technosoft/router","version":"1.0.0","author":{"name":"Tirth M. Jasoliya"},"license":"MIT","_id":"@akshar-technosoft/router@1.0.0","maintainers":[{"name":"tirth_o7o4","email":"tirthjasoliyao7o4@gmail.com"},{"name":"vijay-sutariya","email":"akshartechnosofts@gmail.com"}],"dist":{"shasum":"7d9c7976862d4b7c4d7dbc5d954867fc1f1cdda9","tarball":"https://registry.npmjs.org/@akshar-technosoft/router/-/router-1.0.0.tgz","fileCount":38,"integrity":"sha512-tnCkPe5pyP8D5taTtu/KByPqs0McSRAm7+Dcez4mBbbwOd2TzS62ngaiwKrI4nNP1hBRGEO9FhcDQ+BwLthChA==","signatures":[{"sig":"MEYCIQCwzbvZyGaFvEo3Qm/Gowitz45f3knZVh+/IP8OTsXGJwIhAMK1YQ1f88GfzRhjHtY8aAfGKKXBfiY0xnG0xbSc1Ks5","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":129517},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./core/hooks":{"types":"./dist/core/hooks.d.ts","import":"./dist/core/hooks.js"},"./core/types":{"types":"./dist/core/types.d.ts","import":"./dist/core/types.js"},"./core/utils":{"types":"./dist/core/utils.d.ts","import":"./dist/core/utils.js"},"./core/components":{"types":"./dist/core/components.d.ts","import":"./dist/core/components.js"}},"gitHead":"ff30bb4cc08ecb8d7e418e68a11509e474dbd2f7","scripts":{"dev":"tsup src/index.ts src/core/*.ts src/core/*.tsx --dts --format esm,cjs --watch --clean","build":"tsup src/index.ts src/core/*.ts src/core/*.tsx --dts --format esm,cjs --clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"tirth_o7o4","email":"tirthjasoliyao7o4@gmail.com"},"_npmVersion":"11.4.2","description":"A complete end to end package made for handling complexity of routing of react application","directories":{},"_nodeVersion":"22.18.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","typescript":"^5.9.2","@types/react":"^19.1.10","@types/react-dom":"^19.1.7"},"peerDependencies":{"react":"^19.1.1","react-dom":"^19.1.1","react-router":"^7.8.0"},"_npmOperationalInternal":{"tmp":"tmp/router_1.0.0_1756365433104_0.3933596990642798","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@akshar-technosoft/router","version":"1.0.1","description":"A complete end to end package made for handling complexity of routing of react application","license":"MIT","author":{"name":"Tirth M. Jasoliya"},"type":"module","main":"dist/index.js","types":"dist/index.d.ts","publishConfig":{"access":"public"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./core/components":{"types":"./dist/core/components.d.ts","import":"./dist/core/components.js"},"./core/hooks":{"types":"./dist/core/hooks.d.ts","import":"./dist/core/hooks.js"},"./core/utils":{"types":"./dist/core/utils.d.ts","import":"./dist/core/utils.js"},"./core/types":{"types":"./dist/core/types.d.ts","import":"./dist/core/types.js"}},"scripts":{"build":"tsup src/index.ts src/core/*.ts src/core/*.tsx --dts --format esm,cjs --clean","prepublishOnly":"npm run build","dev":"tsup src/index.ts src/core/*.ts src/core/*.tsx --dts --format esm,cjs --watch --clean"},"peerDependencies":{"react":"^19.1.1","react-dom":"^19.1.1","react-router":"^7.8.0"},"devDependencies":{"@types/react":"^19.1.10","@types/react-dom":"^19.1.7","tsup":"^8.5.0","typescript":"^5.9.2"},"_id":"@akshar-technosoft/router@1.0.1","gitHead":"40860b3b2f041808a7a86dd4bb645f9a8396c6d6","_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-GoAGf+naHz6m3SqLGQUesWKAAeCGiW7Rs9gBsWTZ7nWMK2TFP00Kns1IzI+rf+BDgmUluTqWgnUD+Occ98r7jA==","shasum":"9b1632091c2c8d58ac12b75fa3dc85540bc87c8e","tarball":"https://registry.npmjs.org/@akshar-technosoft/router/-/router-1.0.1.tgz","fileCount":38,"unpackedSize":110053,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDOmn2k4BV00BOy/tUJuNuLPqCNYLrcS+1IZThup8bcfAIgGrWI1uyoJFfUFBZ1F2UCenE7MpSIWue05vDBsVahC+4="}]},"_npmUser":{"name":"neet-0110","email":"neetdhameliya321@gmail.com"},"directories":{},"maintainers":[{"name":"neet-0110","email":"neetdhameliya321@gmail.com"},{"name":"tirth_o7o4","email":"tirthjasoliyao7o4@gmail.com"},{"name":"vijay-sutariya","email":"akshartechnosofts@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/router_1.0.1_1783203588088_0.6426492437190177"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-28T07:17:13.016Z","modified":"2026-07-04T22:19:48.412Z","1.0.0":"2025-08-28T07:17:13.289Z","1.0.1":"2026-07-04T22:19:48.263Z"},"author":{"name":"Tirth M. Jasoliya"},"license":"MIT","description":"A complete end to end package made for handling complexity of routing of react application","maintainers":[{"name":"neet-0110","email":"neetdhameliya321@gmail.com"},{"name":"tirth_o7o4","email":"tirthjasoliyao7o4@gmail.com"},{"name":"vijay-sutariya","email":"akshartechnosofts@gmail.com"}],"readme":"# @akshar-technosoft/router\n\n> ⚡ A thin, fully-typed layer over [React Router](https://reactrouter.com). Register your route tree once — get compile-time-checked paths, typed route params, and IntelliSense on every `Link`, `NavLink`, `Navigate`, and navigation call across your app. Zero runtime overhead: the typing is erased at build time.\n\n---\n\n## 📦 Installation\n\n```bash\nnpm install @akshar-technosoft/router\n# or\nyarn add @akshar-technosoft/router\n```\n\n`react` and `react-router` are peer dependencies — install them in your app.\n\n---\n\n## 🚀 Why this package?\n\n- ✅ **Type-safe paths** — `to=\"/oders\"` (typo) is a compile error. Autocomplete offers every real route.\n- 🧩 **Typed route params** — `to=\"/orders/:id\"` requires `params: { id }`, checked and inferred from the path.\n- 🔗 **Real anchors** — `TypedLink`/`TypedNavLink` render `<a href>`, so ctrl/cmd/middle-click opens a new tab natively.\n- 🧭 **One typed navigate hook** — `typedNavigate(path, opts)`, `typedNavigate(-1)`, or `typedNavigate({ pathname })`.\n- 🪶 **No factories, no glue** — register the route union once with module augmentation; import components directly.\n- 🌐 **URL builder** — `buildPath` interpolates `:params` and appends `query`, with encoding and validation.\n\n---\n\n## 🧩 Setup (three steps)\n\n### 1. Define your route tree\n\nUse `as const satisfies readonly TypedRouteObject[]` so path strings stay **literal** (not widened to `string`) — this is what lets the types read your paths.\n\n```tsx\n// src/routes.tsx\nimport { TypedRouteObject, FlattenRoutes } from \"@akshar-technosoft/router\";\n\nconst routes = [\n  { path: \"/\", element: <Home /> },\n  {\n    path: \"/orders\",\n    children: [\n      { path: \":id\", element: <OrderDetail /> },\n    ],\n  },\n  { path: \"/login\", element: <Login /> },\n] as const satisfies readonly TypedRouteObject[];\n\n// The union of every reachable full path:\nexport type AppRoutes = FlattenRoutes<typeof routes>;\n//   ^? \"/\" | \"/orders\" | \"/orders/:id\" | \"/login\"\n\nexport default routes;\n```\n\n### 2. Register the route union (once)\n\nAugment the package's `Register` interface in a `.d.ts` (or any module file). Every typed API in the package now knows your routes — no factories, no per-app wrappers.\n\n```ts\n// src/types/router.d.ts\nimport type { AppRoutes } from \"@/routes\";\n\ndeclare module \"@akshar-technosoft/router\" {\n  interface Register {\n    routes: AppRoutes;\n  }\n}\n```\n\n> Without this augmentation the package still works — route args just fall back to plain `string` (untyped).\n\n### 3. Mount the router\n\n```tsx\n// src/main.tsx\nimport { createBrowserRouter, RouterProvider } from \"react-router\";\nimport { toRouteObjects } from \"@akshar-technosoft/router\";\nimport routes from \"@/routes\";\n\nconst router = createBrowserRouter(toRouteObjects(routes));\n\ncreateRoot(document.getElementById(\"root\")!).render(<RouterProvider router={router} />);\n```\n\n---\n\n## 📖 API\n\n### `<TypedLink>`\n\nReact Router `<Link>` with a route-checked `to`. Renders a real `<a href>`.\n\n```tsx\nimport { TypedLink } from \"@akshar-technosoft/router\";\n\n<TypedLink to=\"/orders\">All orders</TypedLink>\n\n// Parameterized route — `params` is required and typed from the path:\n<TypedLink to=\"/orders/:id\" routeOptions={{ params: { id: 42 } }}>\n  Open order\n</TypedLink>\n\n// With query string:\n<TypedLink to=\"/orders\" routeOptions={{ query: { status: \"open\", page: 2 } }}>\n  Open orders\n</TypedLink>\n\n// ❌ Compile errors:\n<TypedLink to=\"/order\" />                              // not a route\n<TypedLink to=\"/orders/:id\" />                         // missing params.id\n```\n\nAll other `Link` props (`className`, `state`, `replace`, `onClick`, …) pass through.\n\n### `<TypedNavLink>`\n\nReact Router `<NavLink>` with a route-checked `to`. When `className` is a **string**, an active class (`bg-muted-foreground/30`) is appended automatically. Pass a **callback** for full control.\n\n```tsx\nimport { TypedNavLink } from \"@akshar-technosoft/router\";\n\n<TypedNavLink to=\"/orders\" className=\"px-3 py-2\">Orders</TypedNavLink>\n\n<TypedNavLink\n  to=\"/orders\"\n  className={({ isActive }) => (isActive ? \"font-bold text-primary\" : \"text-muted-foreground\")}\n>\n  Orders\n</TypedNavLink>\n```\n\n### `<TypedNavigate>`\n\nDeclarative redirect — React Router `<Navigate>` with a route-checked `to`. Defaults to **`replace`** (redirects usually should not add a history entry).\n\n```tsx\nimport { TypedNavigate } from \"@akshar-technosoft/router\";\n\nfunction Protected({ user, children }) {\n  if (!user) return <TypedNavigate to=\"/login\" />;\n  return children;\n}\n\n// Push instead of replace:\n<TypedNavigate to=\"/orders/:id\" routeOptions={{ params: { id } }} replace={false} />\n```\n\n### `useTypedNavigate()`\n\nTyped wrapper around `useNavigate`. Returns `{ typedNavigate }`, which accepts three kinds of target.\n\n```tsx\nimport { useTypedNavigate } from \"@akshar-technosoft/router\";\n\nfunction Example() {\n  const { typedNavigate } = useTypedNavigate();\n\n  // 1. A route path — params/query typed and inferred:\n  typedNavigate(\"/orders/:id\", { params: { id: 42 }, query: { tab: \"items\" } });\n\n  // 2. History delta:\n  typedNavigate(-1);                    // back\n  typedNavigate(1);                     // forward\n\n  // 3. An explicit location object:\n  typedNavigate({ pathname: \"/orders\", search: \"?status=open\" }, { replace: true });\n\n  // Redirect after an action (replace so Back doesn't return to the form):\n  typedNavigate(\"/orders\", { replace: true, state: { justCreated: true } });\n}\n```\n\n**Route options:** `params`, `query`, `replace`, `state`.\n\n### `buildPath(path, params?, query?)`\n\nBuild a URL string from a pattern. Interpolates `:params` (URI-encoded) and appends `query`. Throws if a `params` key has no matching `:param`.\n\n```tsx\nimport { buildPath } from \"@akshar-technosoft/router\";\n\nbuildPath(\"/orders/:id\", { id: 42 }, { tab: \"items\" }); // \"/orders/42?tab=items\"\nbuildPath(\"/orders\");                                    // \"/orders\"\n```\n\n### `toRouteObjects(routes)`\n\nCasts a `TypedRouteObject[]` tree to plain React Router `RouteObject[]` for `createBrowserRouter`/`useRoutes`. Runtime no-op.\n\n---\n\n## 🧠 Exported types\n\n| Type | Purpose |\n|------|---------|\n| `TypedRouteObject<Path>` | A `RouteObject` with a literal-typed `path`. Define routes with this. |\n| `FlattenRoutes<T>` | Union of every full path reachable in a route tree. `FlattenRoutes<typeof routes>`. |\n| `PathParams<Path>` | Object type of the `:params` in a path. `PathParams<\"/orders/:id\">` → `{ id: string }`. |\n| `QueryParams` | `Record<string, string \\| number \\| boolean>` for query entries. |\n| `RouteContainsParams<Path>` | `true`/`false` — whether a path has any `:param`. |\n| `Register` | The interface you augment to register your route union. |\n| `RegisteredRoutes` | Resolves to your route union after augmentation (else `string`). |\n\n---\n\n## 🔁 Migrating from the factory-based API\n\nThis release replaces the factory-based API with module augmentation, and drops unused features. **Breaking changes:**\n\n- **Removed** `createTypedComponents` / `createTypedHooks` factories. Import `TypedLink`, `TypedNavLink`, `TypedNavigate`, `useTypedNavigate` **directly** from the package, and register routes via the `Register` interface (see Setup).\n- **Removed** link preloading (`preload`, `preloadOn`) and `injectRoutes` / `getRouteMeta` / route-meta map (was a no-op).\n- **Removed** `typedReplace`, `getQueryParams`, `currentPath` from the navigation hook. Use `typedNavigate(path, { replace: true })`, `new URLSearchParams(location.search)`, and `useLocation()` respectively.\n- `useTypedNavigate()` now returns only `{ typedNavigate }`.\n\nMigration is mechanical: delete the factory glue file, add the `Register` augmentation, and switch imports to the package.\n\n---\n\n## License\n\nMIT © Akshar Technosoft\n","readmeFilename":"README.md"}