{"id":14990353,"url":"https://github.com/mvneerven/pure-spa","last_synced_at":"2026-02-09T13:32:48.019Z","repository":{"id":253806749,"uuid":"844584694","full_name":"mvneerven/pure-spa","owner":"mvneerven","description":"Lit based SPA routing base class","archived":false,"fork":false,"pushed_at":"2024-08-20T10:57:35.000Z","size":96,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T06:31:42.178Z","etag":null,"topics":["lit","router","web","webcomponents"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/pure-spa","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mvneerven.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-08-19T14:56:06.000Z","updated_at":"2024-08-20T12:42:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"d48438eb-fbbb-4eef-a622-bd00b4e828f4","html_url":"https://github.com/mvneerven/pure-spa","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"18b7e34525deffbb9f47dd2d3005aa4f4c4dc3e4"},"previous_names":["mvneerven/pure-spa"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvneerven%2Fpure-spa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvneerven%2Fpure-spa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvneerven%2Fpure-spa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvneerven%2Fpure-spa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mvneerven","download_url":"https://codeload.github.com/mvneerven/pure-spa/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238937490,"owners_count":19555376,"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","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":["lit","router","web","webcomponents"],"created_at":"2024-09-24T14:19:56.200Z","updated_at":"2026-02-09T13:32:47.989Z","avatar_url":"https://github.com/mvneerven.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PureSPA\n\nA routing Lit container (Light DOM) _Base Class_ for modern Web Component-based SPA apps.\n\n## Introduction\n\n`PureSPA` is a Lit Web Component that renders your SPA pages based on an extensible JavaScript configuration file that contains the routes and each route's responsible logic (the SPA pages).\n\n## Main Ingredients\n\n\n- A (Light DOM) [Lit](https://lit.dev/) Element base class to base your apps on.\n- Using the [URLPattern](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) class to match routes and pass dynamic route data.\n- Using [View Transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API) when switching between routes.\n- [Navigation:navigate Event](https://developer.mozilla.org/en-US/docs/Web/API/Navigation/navigate_event) to intercept user navigation.\n\n\u003e Because PureSPA uses relatively new Browser APIs, *polyfills* are provided for functionality that is not yet available in some browsers, like Safari and Firefox.\n\n## Getting started\n\n```cli\n  npm i pure-spa --savedev\n```\n\nCreate a class that extends `PureSPA`, and return a router config in the static `config` property:\n\n```js\nimport { PureSPA } from \"pure-spa\";\nimport { config } from \"./my-app-config.js\";\n\ncustomElements.define(\n  \"my-app\",\n  class MyApp extends PureSPA {\n    /**\n     * Set app.config structure\n     */\n    static get config() {\n      return config;\n    }\n  }\n);\n```\n\n## Sample config: my-app-config.js\n\n```js\nimport { PageAbout } from \"./pages/page-about\";\nimport { PageHome } from \"./pages/page-home\";\n\nexport const config = {\n  routes: {\n    \"/\": {\n      name: \"Home\",\n      run: PageHome,\n    },\n    \"/about\": {\n      run: PageAbout,\n    },\n  },\n};\n```\n\n## Rendering the base SPA structure\n\n`PureSPA`'s Lit render() method renders a route based on the page a user navigates to.\n\n```js\nimport { config } from \"./my-app-config\";\nimport { PureSPA } from \"pure-spa\";\nimport { html } from \"lit\";\nimport { ref, createRef } from \"lit/directives/ref.js\";\n\ncustomElements.define(\n  \"my-app\",\n  class MyApp extends PureSPA {\n    #h1 = createRef();\n\n    static get config() {\n      return config;\n    }\n\n    render() {\n      return html`\n        \u003cheader\u003e\n          \u003ch1 ${ref(this.#h1)}\u003e\u003c/h1\u003e\n        \u003c/header\u003e\n        \u003cmain\u003e${super.render()}\u003c/main\u003e\n      `;\n    }\n\n    firstUpdated() {\n      super.firstUpdated();\n\n      this.on(\"routecomplete\", () =\u003e {\n        this.#h1.value.textContent = this.activeRoute.name;\n      });\n    }\n  }\n);\n```\n\n\n## Nested routes\n\nSub routes are declared as a `routes` nesting on a route:\n\n```js\n \"/program\": {\n    run: PageProgram,\n    routes: {\n      \"/activation\": {\n        run: PageProgramActivation,\n      },\n    },\n```\n\n## Capturing route data\n\nIn the case of an `URLPattern` (RegExp) capturing, the captured data will be passed to a Lit property in the page component:\n\n```js\nimport { PageAbout } from \"./pages/page-about\";\nimport { PageHome } from \"./pages/page-home\";\nimport { PageProfile } from \"./pages/page-profile\";\n\nexport const config = {\n  routes: {\n    \"/\": {\n      name: \"Home\",\n      run: PageHome,\n    },\n    \"/about\": {\n      run: PageAbout,\n    },\n    \"/profile\": {\n      run: PageProfile,\n      routes: {\n        \"/:selector\": {},\n      },\n    },\n  },\n};\n```\n\nIn this case, the `PageProfile` class can retrieve the captured route data using the Lit static properties, using `routeOrigin`:\n\n```js\n  static get properties() {\n    return {\n      profile: { type: Object },\n      selector: { type: String, attribute: true, routeOrigin: 'pathname' },\n      loading: { type: Boolean },\n    };\n  }\n\n```\n\nAs you can see in the example above, if you use this subroute syntax, the parent route's configured component will also be triggered for the sub route.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvneerven%2Fpure-spa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmvneerven%2Fpure-spa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvneerven%2Fpure-spa/lists"}