Gathering detailed insights and metrics for stencil-router-v2
Gathering detailed insights and metrics for stencil-router-v2
Gathering detailed insights and metrics for stencil-router-v2
Gathering detailed insights and metrics for stencil-router-v2
npm install stencil-router-v2
Typescript
Module System
Node Version
NPM Version
57.6
Supply Chain
95.8
Quality
75.5
Maintenance
100
Vulnerability
99.6
License
TypeScript (98.22%)
JavaScript (0.94%)
HTML (0.84%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
236,538
Last Day
53
Last Week
1,435
Last Month
7,327
Last Year
83,744
NOASSERTION License
44 Stars
31 Commits
13 Forks
10 Watchers
19 Branches
9 Contributors
Updated on May 20, 2024
Latest Version
0.6.0
Package Id
stencil-router-v2@0.6.0
Size
7.05 kB
NPM Version
6.14.7
Node Version
14.8.0
Published on
Nov 05, 2020
Cumulative downloads
Total Downloads
Last Day
1.9%
53
Compared to previous day
Last Week
-3.8%
1,435
Compared to previous week
Last Month
41.5%
7,327
Compared to previous month
Last Year
35%
83,744
Compared to previous year
1
1
8
Stencil Router V2 is an experimental new router for stencil that focus in:
This router backs up the document.location
in a @stencil/store
, this way we can respond to changes in document.location is a much simpler, way, not more subscribes, no more event listeners events to connect and disconnect.
Functional Components are the used to collect the list of routes, finally the Switch
renders only the selected route.
1npm install stencil-router-v2 --save-dev
1import { createRouter, Route } from 'stencil-router-v2'; 2 3const Router = createRouter(); 4 5@Component({ 6 tag: 'app-root', 7}) 8export class AppRoot { 9 10 render() { 11 return ( 12 <Host> 13 <Router.Switch> 14 15 <Route path="/"> 16 <h1>Welcome<h1> 17 <p>Welcome to the new stencil-router demo</p> 18 </Route> 19 20 <Route path={/^\/account/}> 21 <app-account></app-account> 22 </Route> 23 24 </Router.Switch> 25 </Host> 26 ); 27 } 28}
1<Host> 2 <Router.Switch> 3 4 <Route path="/" to="/main"/> 5 <Route path={/^account/} to="/error"/> 6 7 </Router.Switch> 8</Host>
Route can take an optional render
property that will pass down the params. This method should be used instead of JSX children.
Regex or functional matches have the chance to generate an object of params when the URL matches.
1import { createRouter, Route, match } from 'stencil-router-v2'; 2 3const Router = createRouter(); 4 5<Host> 6 <Router.Switch> 7 8 <Route 9 path={/^acc(ou)nt/} 10 render={(params) => ( 11 <p>{params[1]}</p> 12 )} 13 /> 14 15 <Route 16 path={match('/blog/:page')} 17 render={({page}) => <blog-post page={page}>} 18 /> 19 20 <Route 21 path={(url) => { 22 if (url.includes('hello')) { 23 return {user: 'hello'} 24 } 25 return undefined; 26 }} 27 render={({user}) => ( 28 <h1>User: {user}</h1> 29 )} 30 /> 31 32 </Router.Switch> 33</Host>
The href()
function will inject all the handles to an native anchor
, without extra DOM.
1import { createRouter, Route, href } from 'stencil-router-v2'; 2 3const Router = createRouter(); 4 5<Host> 6 <Router.Switch> 7 8 <Route path="/main"> 9 <a {...href('/main')} class="my-link">Go to blog</a> 10 </Route> 11 12 <Route path="/blog"> 13 <a {...href('/main')}>Go to main</a> 14 </Route> 15 16 </Router.Switch> 17</Host>
1@Component({ 2 tag: 'app-root', 3}) 4export class AppRoot { 5 6 @State() logged = false; 7 render() { 8 return ( 9 <Host> 10 <Router.Switch> 11 12 {this.logged && ( 13 <Route path="/account"> 14 <app-account></app-account> 15 </Route> 16 )} 17 18 {!this.logged && ( 19 <Route path="/account" to="/error"/> 20 ) 21 22 </Router.Switch> 23 </Host> 24 ); 25 } 26}
Because the router uses @stencil/store
its trivial to subscribe to changes in the locations, activeRoute, or even the list of routes.
1import { createRouter, Route } from 'stencil-router-v2'; 2 3const Router = createRouter(); 4 5@Component({ 6 tag: 'app-root', 7}) 8export class AppRoot { 9 componentWillLoad() { 10 Router.onChange('url', (newValue: InternalRouterState['url'], _oldValue: InternalRouterState['url']) => { 11 // Access fields such as pathname, search, etc. from newValue 12 13 // This would be a good place to send a Google Analytics event, for example 14 }); 15 } 16 17 render() { 18 const activePath = Router.state.activeRoute?.path; 19 20 return ( 21 <Host> 22 <aside> 23 <a class={{'active': activePath === '/main'}}>Main</a> 24 <a class={{'active': activePath === '/account'}}>Account</a> 25 </aside> 26 27 <Router.Switch> 28 29 <Route path="/main"> 30 <h1>Welcome<h1> 31 <p>Welcome to the new stencil-router demo</p> 32 </Route> 33 34 <Route path='/account'> 35 <app-account></app-account> 36 </Route> 37 38 </Router.Switch> 39 </Host> 40 ); 41 } 42}
The routes state includes:
1 url: URL; 2 activeRoute?: RouteEntry; 3 urlParams: { [key: string]: string }; 4 routes: RouteEntry[];
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
Found 3/26 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is archived
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
31 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-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