Gathering detailed insights and metrics for lit-redux-router
Gathering detailed insights and metrics for lit-redux-router
npm install lit-redux-router
Typescript
Module System
Node Version
NPM Version
TypeScript (91.18%)
JavaScript (8.82%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
81,504
Last Day
16
Last Week
256
Last Month
791
Last Year
8,424
MIT License
121 Stars
1,218 Commits
15 Forks
7 Watchers
4 Branches
7 Contributors
Updated on Mar 14, 2025
Latest Version
0.22.0
Package Id
lit-redux-router@0.22.0
Unpacked Size
69.42 kB
Size
18.77 kB
File Count
29
NPM Version
10.2.5
Node Version
21.5.0
Published on
Jan 28, 2024
Cumulative downloads
Total Downloads
Last Day
-48.4%
16
Compared to previous day
Last Week
26.7%
256
Compared to previous week
Last Month
-1.1%
791
Compared to previous month
Last Year
-17.4%
8,424
Compared to previous year
1
3
47
Declarative way of routing for lit powered by pwa-helpers and redux.
A minimal router solution (~1.7 kb Gzipped) that consist in using lit-route
elements and connecting them to the store.
The routing approach is based on the PWA Starter Kit.
Install this library and its peer dependencies
1npm i lit-redux-router lit pwa-helpers redux
Firstly ensure that the redux store has been created with the lazyReducerEnhancer
, which allows for reducers to be installed lazily after initial store setup.
1import { createStore, compose, combineReducers } from 'redux'; 2import { reducer } from './reducer'; 3import { lazyReducerEnhancer } from 'pwa-helpers'; 4 5export const store = createStore(reducer, compose(lazyReducerEnhancer(combineReducers)));
Then the router needs to connect to a redux store.
1import { LitElement, html } from 'lit'; 2import { connectRouter } from 'lit-redux-router'; 3import store from './store.js'; 4 5connectRouter(store);
lit-route
component can render the components when the path attribute matches. The corresponding active lit-route
element will reflect the active attribute.
1class MyApp extends LitElement { 2 render() { 3 return html` 4 <div class="app-content"> 5 <lit-route path="/" active><h1>Home</h1></lit-route> 6 <lit-route path="/about"><h1>About</h1></lit-route> 7 </div> 8 `; 9 } 10} 11customElements.define('my-app', MyApp);
Ideally all content would be in a component and can be passed to lit-route
through a component attribute.
1class AppHome extends LitElement { 2 render() { 3 return html`<h1>Home</h1>`; 4 } 5} 6customElements.define('app-home', AppHome); 7 8class AppAbout extends LitElement { 9 render() { 10 return html`<h1>About</h1>`; 11 } 12} 13customElements.define('app-about', AppAbout); 14 15class MyApp extends LitElement { 16 render() { 17 return html` 18 <div class="app-content"> 19 <lit-route path="/" component="app-home"></lit-route> 20 <lit-route path="/about" component="app-about"></lit-route> 21 </div> 22 `; 23 } 24} 25customElements.define('my-app', MyApp);
lit-route
can map path variables and inject them in the provided component.
1class AppProduct extends LitElement { 2 static get properties() { 3 return { 4 id: String, 5 }; 6 } 7 8 render() { 9 return html`<h1>Product with id: ${this.id}</h1>`; 10 } 11} 12customElements.define('app-product', AppProduct); 13 14class MyApp extends LitElement { 15 render() { 16 return html` 17 <div class="app-content"> 18 <lit-route path="/products/:id" component="app-product"></lit-route> 19 </div> 20 `; 21 } 22} 23customElements.define('my-app', MyApp);
When no path attribute is provided to lit-route
, it will render when no route matches (404)
1class MyApp extends LitElement { 2 render() { 3 return html` 4 <div class="app-content"> 5 <lit-route path="/"><h1>Home</h1></lit-route> 6 <lit-route><h1>404 Not found</h1></lit-route> 7 </div> 8 `; 9 } 10} 11customElements.define('my-app', MyApp);
To trigger navigation without using a link element, the action navigate
can be imported and triggered with the wanted path
1import { navigate } from 'lit-redux-router'; 2import store from './store.js'; 3 4class MyApp extends LitElement { 5 goTo(path) { 6 store.dispatch(navigate(path)); 7 } 8 9 render() { 10 return html` 11 <div class="app-content"> 12 <button @click="${() => this.goTo('/about')}">learn more about us</button> 13 </div> 14 `; 15 } 16} 17customElements.define('my-app', MyApp);
To lazy load a component on route change and optionally show a loading component while waiting for the import to resolve
1import { navigate } from 'lit-redux-router'; 2import store from './store.js'; 3 4class MyApp extends LitElement { 5 render() { 6 return html` 7 <div class="app-content"> 8 <lit-route 9 path="/docs" 10 component="my-docs" 11 .resolve="${() => import('./docs.js')}" 12 loading="my-loading" 13 ></lit-route> 14 </div> 15 `; 16 } 17} 18customElements.define('my-app', MyApp); 19 20class MyLoading extends LitElement { 21 render() { 22 return html` 23 <style> 24 h1 { 25 margin-top: 0; 26 margin-bottom: 16px; 27 } 28 </style> 29 <h1>Loading...</h1> 30 `; 31 } 32} 33 34customElements.define('my-loading', MyLoading);
The window will scroll to top by default, to disable add the attribute scrollDisable
1<lit-route path="/whatever" component="my-whatever" scrollDisable></lit-route>
To scroll to the route element on load, you can set the scrollIntoViewOptions object in the attribute .scrollOpt
1<lit-route 2 path="/whatever" 3 component="my-whatever" 4 .scrollOpt="${{behavior: 'smooth', block:'end', inline:'nearest'}}" 5></lit-route>
Check a more comprehensive example in https://github.com/fernandopasik/lit-redux-router/blob/main/demo/
Start server with example and watch mode for building the library
1npm run start
Run lint and test tasks
1npm run test 2npm run lint
Build the library
1npm run build
Check the full size of the library
1npm run size
Thanks goes to these wonderful people (emoji key):
Fernando Pasik 🐛 💻 📖 🤔 | Grant Hutchinson 🐛 💻 📖 🤔 | Andrew Noblet 🐛 💻 | Zain Afzal 📖 | Christian Sterzl 🐛 💻 | Benjamin Franzke 🐛 💻 | Ramy 🐛 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT (c) 2018 Fernando Pasik
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-03-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More