{"_id":"@aptre/remix-router","_rev":"1-d0e61bb0c03d13dfc08cb171a875ef1f","name":"@aptre/remix-router","dist-tags":{"latest":"1.3.0"},"versions":{"1.3.0":{"name":"@aptre/remix-router","version":"1.3.0","keywords":["remix","router","location"],"author":{"name":"Remix Software","email":"hello@remix.run"},"license":"MIT","_id":"@aptre/remix-router@1.3.0","maintainers":[{"name":"paralin","email":"christian@paral.in"}],"homepage":"https://github.com/aperturerobotics/remix-react-router#readme","bugs":{"url":"https://github.com/aperturerobotics/remix-react-router/issues"},"dist":{"shasum":"898a9e4f1e2e90ddadf5fc7e3b13f6a2cb013af3","tarball":"https://registry.npmjs.org/@aptre/remix-router/-/remix-router-1.3.0.tgz","fileCount":12,"integrity":"sha512-KMH9wJm71FjVEOtQgtgVtJA03eWxATuu40AQB0iZCRc78AWyNCr0dIQAUCNx3PgbqKQ3bR3N1ttYxcURd5wwnA==","signatures":[{"sig":"MEYCIQD7qoiFO+EmF6vCbmZpdigrMhDKxXPEpi1xYNXSO+lTnwIhAJLL1QuYete/kX9Zr2UW1tNm1EpWc0fxIURD/Ez+DKXU","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":427316},"main":"./dist/router.cjs.js","types":"./dist/index.d.ts","unpkg":"./dist/router.umd.min.js","module":"./dist/router.js","engines":{"node":">=14.0.0"},"gitHead":"eb14f2e5b091d56bea3d0f578ccb3a4e07f208a6","scripts":{"build":"npm run clean && npm run build:lib && npm run build:types","clean":"rimraf ./dist","build:lib":"npm run build:esbuild -- --outfile=./dist/index.mjs ./index.ts","build:min":"npm run build:lib:min && npm run build:types","build:types":"tsc --emitDeclarationOnly --declaration --outDir dist/","build:esbuild":"esbuild --bundle --external:react --external:react-dom --format=esm --define:__DEV__=false --tree-shaking=true --target=es2022 --platform=browser","build:lib:min":"npm run build:lib -- --minify"},"_npmUser":{"name":"paralin","email":"christian@paral.in"},"repository":{"url":"git+https://github.com/aperturerobotics/remix-react-router.git","type":"git","directory":"packages/router"},"_npmVersion":"10.9.0","description":"Nested/Data-driven/Framework-agnostic Routing","directories":{},"sideEffects":false,"_nodeVersion":"23.2.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/remix-router_1.3.0_1732759743104_0.5667774351270616","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"time":{"created":"2024-11-28T02:09:02.908Z","modified":"2024-11-29T23:02:21.126Z","1.3.0":"2024-11-28T02:09:03.431Z"},"bugs":{"url":"https://github.com/aperturerobotics/remix-react-router/issues"},"author":{"name":"Remix Software","email":"hello@remix.run"},"license":"MIT","homepage":"https://github.com/aperturerobotics/remix-react-router#readme","keywords":["remix","router","location"],"repository":{"url":"git+https://github.com/aperturerobotics/remix-react-router.git","type":"git","directory":"packages/router"},"description":"Nested/Data-driven/Framework-agnostic Routing","maintainers":[{"name":"paralin","email":"christian@paral.in"}],"readme":"# Remix Router\n\nThe `@aptre/remix-router` package is a framework-agnostic routing package (sometimes referred to as a browser-emulator) that serves as the heart of [React Router][react-router] and [Remix][remix] and provides all the core functionality for routing coupled with data loading and data mutations. It comes with built-in handling of errors, race-conditions, interruptions, cancellations, lazy-loading data, and much, much more.\n\nIf you're using React Router, you should never `import` anything directly from the `@aptre/remix-router` - you should have everything you need in `react-router-dom` (or `react-router`/`react-router-native` if you're not rendering in the browser). All of those packages should re-export everything you would otherwise need from `@aptre/remix-router`.\n\n> [!WARNING]\n>\n> This router is a low-level package intended to be consumed by UI layer routing libraries. You should very likely not be using this package directly unless you are authoring a routing library such as [`react-router-dom`][react-router-repo] or one of it's other [UI ports][remix-routers-repo].\n\n## API\n\nA Router instance can be created using `createRouter`:\n\n```js\n// Create and initialize a router.  \"initialize\" contains all side effects\n// including history listeners and kicking off the initial data fetch\nlet router = createRouter({\n  // Required properties\n  routes: [{\n    path: '/',\n    loader: ({ request, params }) => { /* ... */ },\n    children: [{\n      path: 'home',\n      loader: ({ request, params }) => { /* ... */ },\n    }]\n  },\n  history: createBrowserHistory(),\n\n  // Optional properties\n  basename, // Base path\n  mapRouteProperties, // Map framework-agnostic routes to framework-aware routes\n  future, // Future flags\n  hydrationData, // Hydration data if using server-side-rendering\n}).initialize();\n```\n\nInternally, the Router represents the state in an object of the following format, which is available through `router.state`. You can also register a subscriber of the signature `(state: RouterState) => void` to execute when the state updates via `router.subscribe()`;\n\n```ts\ninterface RouterState {\n  // False during the initial data load, true once we have our initial data\n  initialized: boolean;\n  // The `history` action of the most recently completed navigation\n  historyAction: Action;\n  // The current location of the router.  During a navigation this reflects\n  // the \"old\" location and is updated upon completion of the navigation\n  location: Location;\n  // The current set of route matches\n  matches: DataRouteMatch[];\n  // The state of the current navigation\n  navigation: Navigation;\n  // The state of any in-progress router.revalidate() calls\n  revalidation: RevalidationState;\n  // Data from the loaders for the current matches\n  loaderData: RouteData;\n  // Data from the action for the current matches\n  actionData: RouteData | null;\n  // Errors thrown from loaders/actions for the current matches\n  errors: RouteData | null;\n  // Map of all active fetchers\n  fetchers: Map<string, Fetcher>;\n  // Scroll position to restore to for the active Location, false if we\n  // should not restore, or null if we don't have a saved position\n  // Note: must be enabled via router.enableScrollRestoration()\n  restoreScrollPosition: number | false | null;\n  // Proxied `preventScrollReset` value passed to router.navigate()\n  preventScrollReset: boolean;\n}\n```\n\n### Navigations\n\nAll navigations are done through the `router.navigate` API which is overloaded to support different types of navigations:\n\n```js\n// Link navigation (pushes onto the history stack by default)\nrouter.navigate(\"/page\");\n\n// Link navigation (replacing the history stack)\nrouter.navigate(\"/page\", { replace: true });\n\n// Pop navigation (moving backward/forward in the history stack)\nrouter.navigate(-1);\n\n// Form submission navigation\nlet formData = new FormData();\nformData.append(key, value);\nrouter.navigate(\"/page\", {\n  formMethod: \"post\",\n  formData,\n});\n\n// Relative routing from a source routeId\nrouter.navigate(\"../../somewhere\", {\n  fromRouteId: \"active-route-id\",\n});\n```\n\n### Fetchers\n\nFetchers are a mechanism to call loaders/actions without triggering a navigation, and are done through the `router.fetch()` API. All fetch calls require a unique key to identify the fetcher.\n\n```js\n// Execute the loader for /page\nrouter.fetch(\"key\", \"/page\");\n\n// Submit to the action for /page\nlet formData = new FormData();\nformData.append(key, value);\nrouter.fetch(\"key\", \"/page\", {\n  formMethod: \"post\",\n  formData,\n});\n```\n\n### Revalidation\n\nBy default, active loaders will revalidate after any navigation or fetcher mutation. If you need to kick off a revalidation for other use-cases, you can use `router.revalidate()` to re-execute all active loaders.\n\n### Future Flags\n\nWe use _Future Flags_ in the router to help us introduce breaking changes in an opt-in fashion ahead of major releases. Please check out the [blog post][future-flags-post] and [React Router Docs][api-development-strategy] for more information on this process. The currently available future flags in `@aptre/remix-router` are:\n\n| Flag                     | Description                                                               |\n| ------------------------ | ------------------------------------------------------------------------- |\n| `v7_normalizeFormMethod` | Normalize `useNavigation().formMethod` to be an uppercase HTTP Method     |\n| `v7_prependBasename`     | Prepend the `basename` to incoming `router.navigate`/`router.fetch` paths |\n\n[react-router]: https://reactrouter.com\n[remix]: https://remix.run\n[react-router-repo]: https://github.com/remix-run/react-router\n[remix-routers-repo]: https://github.com/brophdawg11/remix-routers\n[api-development-strategy]: https://reactrouter.com/en/main/guides/api-development-strategy\n[future-flags-post]: https://remix.run/blog/future-flags\n","readmeFilename":"README.md"}