
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
zzRouter is a tiny javascript router component to make it easy build Single Page Applications.
Use it if you want to build a SPA using vanilla Javascript and if you don't want to use any heavy javascript framework. You can also use CSS directly or your favourite CSS framework.
No support for very old browsers. No polyfills. zzRouter should work with any not too old browser. It should work with any browser that supports:
zzRouter is registered as a package on npm. This is the recomended way of downloading it. You can install the latest version of zzRouter with the npm CLI command:
npm install zzrouter
First of all, 2 files are needed to be added to the HTML page, a JS file and a CSS file. Using ES modules:
<script type="module" src="zzRouterSampleESM.js"></script>
<link href="zzRouter.css" rel="stylesheet">
Let's import the zzRouter module in the javascript file:
import { zzRouter } from '/node_modules/zzrouter/index.js';
You can also use CommonJS:
const zzRouter = require( 'zzrouter' );
For production you might use built versions in dist directory:
Let's see some examples.
An example of routes with content defined as string literals. This SPA consist of a home page, a links page and a 404 error page:
const routes = {
// Home page
{
id: '[home]',
content: `
<h1>zzRouter sample</h1>
<div class="page-content">
<h3>Home page</h3>
<p>
This is the Home page
</p>
<ul id="home_links">
<li>
<a href="!links">Links</a>. Go to links page.
</li>
</ul>
</div>
`
},
// Links page
{
id: 'links',
content: `
<h1>zzRouter sample</h1>
<div>
<a href="!">Home</a>
</div>
<div class="page-content">
<h3>Links page</h3>
<p>
This is the links page
</p>
<ul>
<li>
<a href="https://github.com/davidcana/zzRouter">zzRouter</a>.
A simple router component to make it easy build Single Page Applications.
</li>
<li>
<a href="https://davidcana.github.io/ZPT-JS/">ZPT-JS</a>.
Zenon Page Templates - JS (ZPT-JS) is a Javascript implementation of Zope Page Templates (ZPT).
</li>
<li>
<a href="https://github.com/davidcana/ZPT-Java">ZPT-Java</a>.
JPT is a Java implementation of Zope Page Templates (ZPT).
</li>
<li>
<a href="https://github.com/davidcana/zzDOM">zzDOM</a>.
A tiny javascript API that implements only the DOM functions of jquery including chaining.
</li>
</ul>
</div>
`
},
// Default route (404 page)
{
id: '[404]',
content: `
<h1>zzRouter sample</h1>
<div>
<a href="!">Home</a>
</div>
<div class="page-content">
<h3>404 page</h3>
<p>
Sorry
</p>
<p>
Requested content not found.
</p>
</div>
`
}
};
// Start router
zzRouter.start({
routes: routes
});
An example of lazy loading of HTML from URLs. Providing pages/home.html, pages/links.html and pages/404error.html contain the previuosly defined HTML:
const routes = {
// Home page
{
id: '[home]',
url: 'pages/home.html'
},
// Links page
{
id: 'links',
url: 'pages/links.html'
},
// Default route (404 page)
{
id: '[404]',
url: 'pages/404error.html'
}
};
// Start router
zzRouter.start({
routes: routes
});
If we prefer to preload pages use the preloadPagesOnStart option:
// Start router
zzRouter.start({
routes: routes,
preloadPagesOnStart: true
});
Let's see what happens when an internal link is clicked:
zzRouter includes a short list of CSS animations to use in animationOut and animationIn configuration options. They have been generated by Animista. The list of animations is:
You can use your custom CSS animations too.
The list of events:
The list of available configuration options (default values in brackets).
The only required configuration option is:
Options in lower case are recommended to be customized:
Options in upper case are not recommended to be customized, but do it if you know what you are doing:
FAQs
A simple router component to make it easy build Single Page Applications.
We found that zzrouter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.