Installations
npm install stencil-router-v2
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
14.8.0
NPM Version
6.14.7
Score
57.6
Supply Chain
95.8
Quality
75.5
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (98.22%)
JavaScript (0.94%)
HTML (0.84%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
manucorporat
Download Statistics
Total Downloads
236,538
Last Day
53
Last Week
1,435
Last Month
7,327
Last Year
83,744
GitHub Statistics
NOASSERTION License
44 Stars
31 Commits
13 Forks
10 Watchers
19 Branches
9 Contributors
Updated on May 20, 2024
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
236,538
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
1
Dev Dependencies
8
stencil-router-v2
Stencil Router V2 is an experimental new router for stencil that focus in:
- Lightweight (600bytes)
- Treeshakable (not used features are not included in the final build)
- Simple, provide the bare mininum but it make it extendable with hooks.
- No DOM: Router is not render any extra DOM element, to keep styling simple.
- Fast: As fast and lightweight as writing your own router with if statements.
How does it work?
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.
Install
1npm install stencil-router-v2 --save-dev
Examples
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}
Redirects
1<Host> 2 <Router.Switch> 3 4 <Route path="/" to="/main"/> 5 <Route path={/^account/} to="/error"/> 6 7 </Router.Switch> 8</Host>
Params
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>
Links
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>
Dynamic routes (guards)
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}
Subscriptions to route changes
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
- Info: security policy file detected: github.com/ionic-team/.github/SECURITY.md:1
- Info: Found linked content: github.com/ionic-team/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/ionic-team/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/ionic-team/.github/SECURITY.md:1
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
Found 3/26 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/ionic-team/stencil-router-v2/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/ionic-team/stencil-router-v2/main.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:21
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Reason
31 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
3.2
/10
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