{"id":15792703,"url":"https://github.com/nfour/xroute","last_synced_at":"2025-10-14T17:17:55.169Z","repository":{"id":57402228,"uuid":"318735890","full_name":"nfour/xroute","owner":"nfour","description":"Typed MobX browser router","archived":false,"fork":false,"pushed_at":"2025-07-19T07:41:55.000Z","size":725,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-02T19:34:21.855Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nfour.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-05T08:10:28.000Z","updated_at":"2025-07-14T03:50:04.000Z","dependencies_parsed_at":"2024-05-22T04:25:16.789Z","dependency_job_id":"e7f33807-713c-49b8-9c56-2ecc78bd436c","html_url":"https://github.com/nfour/xroute","commit_stats":{"total_commits":120,"total_committers":2,"mean_commits":60.0,"dds":"0.050000000000000044","last_synced_commit":"61f1b34762cbfd6671017cc282fb5a1c86bed54e"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/nfour/xroute","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfour%2Fxroute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfour%2Fxroute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfour%2Fxroute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfour%2Fxroute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nfour","download_url":"https://codeload.github.com/nfour/xroute/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfour%2Fxroute/sbom","scorecard":{"id":682654,"data":{"date":"2025-08-11","repo":{"name":"github.com/nfour/xroute","commit":"3256abc87c912e30c0a6e4e60b4f69ebfd6cccdc"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":8,"reason":"10 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 8","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":8,"reason":"2 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99","Warn: Project is vulnerable to: GHSA-jgmv-j7ww-jx2x"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T23:41:26.909Z","repository_id":57402228,"created_at":"2025-08-21T23:41:26.909Z","updated_at":"2025-08-21T23:41:26.909Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020077,"owners_count":26086806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-04T23:02:59.021Z","updated_at":"2025-10-14T17:17:55.151Z","avatar_url":"https://github.com/nfour.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XRoute\n\nMobx powered `History` router, with types.\n\n+ [Features](#features)\n+ [Usage](#usage)\n+ [Troubleshooting](#troubleshooting)\n  + [Typescript errors](#typescript-errors)\n\n\n## Features\n\n- [x] Declarative observable wrapper over the `History` interface\n- [x] Type safe `pathname` params\n- [x] Type safe `search` params via `qs` serialization\n- [x] Type safe `hash` string\n- [x] Workarounds for some known issues with History: [Here](https://github.com/ReactTraining/history/issues/811)\n- [x] Route inheritance for nesting routes \n\n\n\n## Usage\n\n- [x] Requires \u003e= Mobx@6\n\n\u003e See the [stories for usage examples](./stories/mobx.stories.tsx)\n\n- [docs/routeDefinition.ts](./docs/routeDefinition.ts)\n\n![image](https://github.com/nfour/xroute/assets/2108452/c7b118f8-f180-4e1b-99ca-15b130b71470)\n\n```tsx\nimport { createBrowserHistory } from 'history'\nimport { XRoute, XRouter } from 'xroute'\n\n/** A simple route, matches the `/`, the root page */\nexport const HomeRoute = XRoute('home')\n  .Resource('/') // /\n  .Type\u003c{\n    pathname: {}\n    search: {}\n  }\u003e()\n\nexport const AdminRoute = XRoute('admin')\n  .Resource(\n    `/admin`, // /admin\n  )\n  .Type\u003c{\n    pathname: {}\n    search: { isAdvancedView?: boolean }\n  }\u003e()\n\nenum AdminAnalyticsSubSections {\n  TopPages = 'topPages',\n  TopUsers = 'topUsers',\n  RawData = 'rawData',\n}\n\nconst AdminAnalyticsSubsectionsURI = `:subSection(${AdminAnalyticsSubSections.TopPages}|${AdminAnalyticsSubSections.TopUsers}|${AdminAnalyticsSubSections.RawData})?`\n\n//\n// OR:\n//    if you dont care about type safety, do this:\n//\n\nconst AdminAnalyticsSubsectionsURILoose = `:subSection(${Object.values(\n  AdminAnalyticsSubSections,\n).join('|')})?` as const\n\nexport const AdminAnalyticsRoute = AdminRoute.Extend('adminAnalytics')\n  .Resource(`/analytics/${AdminAnalyticsSubsectionsURI}`) // /admin/analytics/:subSection(topPages|topUsers|rawData)\n  .Type\u003c{\n    pathname: { subSection?: AdminAnalyticsSubSections }\n    search: {}\n  }\u003e()\n\nexport const AdminUsersRoute = AdminRoute.Extend('adminUsers')\n  .Resource(`/users`) // /admin/users\n  .Type\u003c{\n    pathname: {}\n\n    // You don't need to use the pathname at all if you want to keep it simple\n    // Can even nest objects and arrays.\n    search: {\n      userId?: string // ends up as ?userId=123\n      editor?: {\n        line?: string\n        activeToolId?: string\n        selectedItems?: string[]\n      } // ?editor[line]=1\u0026editor[activeToolId]=2\u0026editor[selectedItems]=3\u0026editor[selectedItems]=4\n    }\n  }\u003e()\n\nexport const NotFoundRoute = XRoute('notFound')\n  .Resource('/:someGarbage(.*)?') // /:someGarbage(.*)?\n  .Type\u003c{\n    pathname: {\n      /** The pathname that didnt match any route */\n      someGarbage?: string\n    }\n    search: {}\n  }\u003e()\n\nexport function createRouter() {\n  return new XRouter(\n    // Order matters, notice the `notFound` route is at the end, to act as a fallback\n    [\n      AdminAnalyticsRoute, // /admin/analytics/topPages\n      AdminUsersRoute, // /admin/users?userId=123\u0026editor[line]=1\u0026editor[activeToolId]=2\u0026editor[selectedItems]=3\u0026editor[selectedItems]=4\n      AdminRoute, // /admin\n      HomeRoute, // /\n      NotFoundRoute, // /asdaskjdkalsdjklasd\n    ],\n    createBrowserHistory(),\n  )\n}\n\n```\n\n- [docs/fullExample.tsx](./docs/fullExample.tsx)\n\n```tsx\nimport { createHashHistory } from 'history'\nimport { autorun, makeAutoObservable, reaction } from 'mobx'\nimport { observer } from 'mobx-react-lite'\nimport * as React from 'react'\nimport { XRoute, XRouter } from 'xroute'\n\n//\n// Define some routes\n//\n\nconst HomeRoute = XRoute('home')\n  .Resource('/') // Optional language param, eg. /en or /\n  .Type\u003c{\n    pathname: {}\n    search: { language?: 'en' | 'da' | 'de' }\n  }\u003e()\n\nconst UserProfileRoute = HomeRoute.Extend('userProfile')\n  .Resource('/user/:userId') // Required language, eg. /da/user/11\n  .Type\u003c{\n    pathname: { userId: string }\n    search: { profileSection: 'profile' | 'preferences' }\n  }\u003e()\n\nconst router = new XRouter([UserProfileRoute, HomeRoute], createHashHistory())\n\nexport type MyXRouter = typeof router\n\n// Log some changes\nautorun(() =\u003e console.log('Active route:', router.route))\n\n// Navigate to: /?language=en\nrouter.routes.home.push({ pathname: { language: 'en' } })\n\n// Get the pathname, eg. to put inside an \u003ca href=\"\" /\u003e\nconst homeDaUri = router.routes.home.toUri({ pathname: { language: 'da' } }) // \"/da\"\n\n// Navigates to: /user/11?language=en\nrouter.routes.userProfile.push({\n  pathname: { userId: '11' },\n  search: { language: 'en' },\n})\n\n// Just change the language in the active route.\n// This works as long as the parameter is shared between all routes.\n// Navigates to: /user/11?language=da\nrouter.route?.push({ pathname: { language: 'da' } })\n\n// Re-use the current language\n// Navigates to: /?language=da\nrouter.routes.home.push({\n  search: { language: router.route?.search.language },\n})\n\n// Provide a route object to route from anywhere:\n// Navigate to: /de/user/55\nrouter.push(UserProfileRoute, {\n  pathname: { userId: '55' },\n  search: { language: 'de' },\n})\n\n// Read route properties:\n\n/** This must be read from the `routes.userProfile` for the type to be consistent */\nrouter.routes.userProfile.pathname?.userId // =\u003e '55'\n\n/** Because `language` is available on all routes, we can read it from the active route at `router.route` */\nrouter.route?.search?.language\n\nclass UserProfilePage {\n  constructor(private router: MyXRouter) {\n    this.router = router\n\n    makeAutoObservable(this)\n  }\n\n  get route() {\n    return this.router.routes.userProfile\n  }\n\n  get userId() {\n    return this.route.pathname?.userId\n  }\n\n  get profileSection() {\n    return this.route.search?.profileSection\n  }\n\n  setUserId(userId: string) {\n    // Uses current route params\n    this.route.push({ pathname: { userId } })\n\n    //\n    // or\n    //\n    // Explicitly use previous params...\n    this.route.pushExact((uri) =\u003e ({\n      ...uri,\n      pathname: { ...uri.pathname, userId },\n    }))\n  }\n\n  setProfileSection(profileSection: this['profileSection']) {\n    this.route.push({ search: { profileSection } }) // sets ?profileSection=\"\"\n  }\n}\n\n// Play around with user profile:\nvoid (async () =\u003e {\n  const userProfilePage = new UserProfilePage(router)\n\n  userProfilePage.userId // 55\n\n  userProfilePage.setUserId('200')\n\n  await new Promise((r) =\u003e setTimeout(r, 50)) // Give it time to update the URL and come back...\n\n  userProfilePage.userId // 200\n})()\n\nconst Component = observer(() =\u003e {\n  const [router] = React.useState(\n    () =\u003e new XRouter([UserProfileRoute, HomeRoute], createHashHistory()),\n  )\n\n  return (\n    \u003c\u003e\n      \u003cnav\u003eActive Language: {router.route?.search.language}\u003c/nav\u003e\n      {router.route?.key === 'home' \u0026\u0026 \u003cdiv\u003eHome Page!\u003c/div\u003e}\n      {\n        // Or do this:\n      }\n      {router.routes.userProfile.isActive \u0026\u0026 (\n        \u003cdiv\u003e\n          User Profile! UserID: {router.routes.userProfile.pathname?.userId}\n        \u003c/div\u003e\n      )}\n    \u003c/\u003e\n  )\n})\n\nconst listenToUserProfileRoute = () =\u003e {\n  let previousIsActive: boolean\n\n  reaction(\n    () =\u003e router.routes.userProfile.isActive,\n    (isActive) =\u003e {\n      if (isActive === previousIsActive) return // Ignore same state\n\n      previousIsActive = isActive\n\n      if (isActive) {\n        // on enter route\n        // ...\n      } else {\n        // on exit route\n        // ...\n      }\n    },\n  )\n}\n\n```\n\n## Troubleshooting\n\n### Typescript errors\n\nAre you getting an error like this?\n\n```\nThe inferred type of \"X\" cannot be named without a reference to \"Y\"\n```\n\nThis can be an issue now that the project uses `zod` for schema generation support.\n\nIt can help to update your tsconfig.json with this:\n\n```json\n{\n  \"compilerOptions\": {\n    \"moduleResolution\": \"NodeNext\",\n    \"module\": \"NodeNext\",\n  }\n}\n\n```\n\nOr if that doesnt work, add one of these imports anywhere in your project\n\n```ts\nimport 'xroute/XRouteSchema'\n// or if that doesnt work in your older typescript project, use the ugly path:\nimport 'xroute/x/esm/XRouteSchema'\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfour%2Fxroute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnfour%2Fxroute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfour%2Fxroute/lists"}