Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
can-route
Advanced tools
[![Build Status](https://travis-ci.org/canjs/can-route.png?branch=master)](https://travis-ci.org/canjs/can-route)
Note: This is the CanJS can-route module. The old
can-route
has been renamed to did-route. Many thanks to @michaelrhodes for letting us use thecan-route
module name.
route(template [, defaults])
Create a route matching rule. Optionally provide defaults that will be applied to the [can-map] when the route matches.
route(":page", { page: "home" });
Will apply cart when the url is #cart
and home when the url is #
.
{String}
:
the fragment identifier to match. The fragment identifier
should start with either a character (a-Z) or colon (:). Examples:route(":foo")
route("foo/:bar")
{Object}
:
An object of default values.returns {can.route}
:
route.map(MapConstructor)
Binds can-route to an instance based on a constructor. A new instance will be created and bound to:
var ViewModel = Map.attr({
define: {
page: {
set: function(page){
if(page === "user") {
this.verifyLoggedIn();
}
return page;
}
}
}
});
route.map(ViewModel);
{can-map}
:
A can-map constructor function. A new can-map instance will be created and used as the can-map internal to can-route.route.map(mapInstance)
Bind can-route to an instance of a map.
var map = new Map({
page: "home"
});
route.map(map);
map.attr("page", "user");
// location.hash -> "#user"
{can-map}
:
A can-map instance, used as the can-map internal to can-route.route.param(data)
{data}
:
The data to populate the route with.{String}
:
The route, with the data populated in it.route.deparam(url)
Extract data from a url, creating an object representing its values.
route(":page");
var result = route.deparam("page=home");
console.log(result.page); // -> "home"
{String}
:
A route fragment to extract data from.{Object}
:
An object containing the extracted data.route.ready()
Sets up the two-way binding between the hash and the can-route observable map and sets the route map to its initial values.
route(":page", { page: "home" }));
route.ready();
route.attr("page"); // -> "home"
{canRoute}
:
The can-route object.route.url(data [, merge])
Make a URL fragment that when set to window.location.hash will update can-route's properties
to match those in data
.
route.url({ page: "home" });
// -> "#!page=home"
{Object}
:
The data to populate the route with.{Boolean}
:
Whether the given options should be merged into the current state of the route.{String}
:
The route URL and query string.route.link(innerText, data, props [, merge])
Make an anchor tag (<A>
) that when clicked on will updatecanRoute's properties
to match those in data
.
{Object}
:
The text inside the link.{Object}
:
The data to populate the route with.{Object}
:
Properties for the anchor other than href
.{Boolean}
:
Whether the given options should be merged into the current state of the route.{String}
:
A string with an anchor tag that points to the populated route.To make a build of the distributables into dist/
in the cloned repository run
npm install
node build
Tests can run in the browser by opening a webserver and visiting the test.html
page.
Automated tests that run the tests from the command line in Firefox can be run with
npm test
FAQs
Observable front-end application routing for CanJS.
We found that can-route demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 16 open source maintainers 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
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.