
Research
/Security News
Shai Hulud Strikes Again (v2)
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.
@voliware/router-element
Advanced tools
Two simple elements, <router-element> and <route-element> that manage your page's view state and address bar history. You can use these elements to create an SPA or just a simple element with many nested views.
<router-element nav="#nav1, #nav2">
<route-element url="/" ></route-element>
<route-element url="/users/login" display="flex"></route-element>
<route-element url="/users/register"></route-element>
<route-element url="/users/account/settings"></route-element>
<route-element url="/movies"></route-element>
<route-element url="/games"></route-element>
</router-element>
This is an example of a simple SPA. At the top is a <router-element> which will manage the routing, address bar, and history. The rest of the elements are <route-element>s which organize views by URL. The only function call that may be needed is route(url). This can be called from <router-element>.
const router = document.querySelector('router-element');
router.route('/users/account/settings');
This will reveal the /users/account/settings route and hide all others, which are hidden by default.
You can listen to the <router-element> event routed to take some action when a URL has been routed.
const router = document.querySelector('router-element');
router.addEventListener('routed', event => {
console.log(`Went to this ${event.detail} route`);
});
router.route('/users/account/settings');
You can listen to the <router-element> event notfound to take some action when a URL has not been found.
const router = document.querySelector('router-element');
router.addEventListener('notfound', event => {
console.log(`${event.detail} route does not exist!`);
});
router.route('/users/badurl');
You can set the display attribute for <route-element> to change what display style it uses when it is revealed
<!-- When this route is displayed, it will use the flex style -->
<route-element url="/users/stats" display="flex"></route-element>
You can set some attributes for <router-element> for some minor behaviour differences
<router-element back="false"> will prevent intercepting the back navigation action from changing the current route.
<router-element history="false"> will prevent routing from updating the address bar.
<router-element auto="false"> will prevent the router from routing to the window location pathname on page load. To instead do this manually, call initialize() whenever your application is ready.
<router-element slugs="false"> will prevent the router from stripping slug-like text at the end of a URL. For example /blogs/post/this-is-a-slug would become /blogs/post.
const router = document.querySelector('router-element');
router.initialize();
The <router-element> can also connect to one or more simple navigation elements. For example, suppose the following navigational HTML
<div id="navtop">
<div url="/" class="route-element-nav"></div>
<div url="/users" class="route-element-nav">
<div url="/users/account" class="route-element-nav">
<div url="/users/account/settings" class="route-element-nav"></div>
</div>
</div>
<div url="/movies" class="route-element-nav"></div>
<div url="/games" class="route-element-nav"></div>
</div>
Notice how each nav in question has a class="route-element-nav. This is the only attribute required to be a valid navigation element. To connect this nav to a <route-element> add a nav="" attribute with one or more ids. Multiple ids are supported in the case that there may be two identical menus in the HTML, such as a top and bottom navigation system.
<router-element nav="#navtop, #navbottom"></router-element>
When a url is navigated to, <router-element> will set the appropriate nav's class to route-element-nav-active and remove the same class from all others. The only other step is to define a class in your stylesheet somewhere like
.route-element-nav-active {
color: white;
}
If you have a nested element inside a <route-element> and it does something that should trigger a route change, you can simply dispatch a route event with the detail set to the desired url and bubble set to true. The <router-element> will handle it if it has a matching URL.
const btn = document.getElementById('button');
btn.addEventListener('click', () => {
this.dispatchEvent(new CustomEvent('route', {detail: '/users/friends', bubbles: true}));
});
You can tie in to route changes, to do things like initial a component, like so
const router = document.querySelector('router-element');
router.addEventListener('route', event => {
if(event.detail === '/user/stats'){
users_stats_element.renderStats();
}
})
findRoutes() is an internal function that looks through child elements to find all <route-element>s.
findRoutes() function which will recapture all <route-elements>findRoutes() checks each child to be an instanceof RouteElementurl attributes also triggers a call to findRoutes()npm install @voliware/router-element
You can then build it into your own distribution file or serve it via
./node_modules/@voliware/router-element/dist/router-element.min.js
./node_modules/@voliware/router-element/dist/router-element.min.css
Or you can use a CDN
<script src="https://cdn.jsdelivr.net/npm/@voliware/router-element/dist/router-element.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@voliware/router-element/dist/router-element.min.css"/>
Or you can simply download the files in the /dist folder off the repo.
Run npm run test.
Fragmented <route-element>s that aren't all organized in the HTML as direct children. This would be useful for HTML that resides in one file and has become very nested.
FAQs
A simple router element built with custom elements
The npm package @voliware/router-element receives a total of 1 weekly downloads. As such, @voliware/router-element popularity was classified as not popular.
We found that @voliware/router-element demonstrated a not healthy version release cadence and project activity because the last version was released 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.

Research
/Security News
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.