Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

preact-router

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

preact-router - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

2

dist/preact-router.js

@@ -1,3 +0,3 @@

(function(global,factory){if(typeof define === 'function' && define.amd){define(['exports','preact'],factory);}else if(typeof exports !== 'undefined'){factory(exports,require('preact'));}else {var mod={exports:{}};factory(mod.exports,global.preact);global.preactRouter = mod.exports;}})(this,function(exports,_preact){'use strict';exports.__esModule = true;var _extends=Object.assign || function(target){for(var i=1;i < arguments.length;i++) {var source=arguments[i];for(var key in source) {if(Object.prototype.hasOwnProperty.call(source,key)){target[key] = source[key];}}}return target;};exports.route = route;function _objectWithoutProperties(obj,keys){var target={};for(var i in obj) {if(keys.indexOf(i) >= 0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i] = obj[i];}return target;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function');}}function _inherits(subClass,superClass){if(typeof superClass !== 'function' && superClass !== null){throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var routers=[];function route(url){if(history){history.pushState(null,null,url);}routeTo(url);}function routeTo(url){routers.forEach(function(router){return router.routeTo(url);});}function getCurrentUrl(){return '' + (location.pathname || '') + (location.search || '');}if(typeof addEventListener === 'function'){addEventListener('popstate',function(){return routeTo(getCurrentUrl());});}function handleLinkClick(e){route(this.getAttribute('href'));if(e.stopImmediatePropagation)e.stopImmediatePropagation();e.stopPropagation();e.preventDefault();return false;}var Link=function Link(_ref){var children=_ref.children;var props=_objectWithoutProperties(_ref,['children']);return _preact.h('a',_extends({},props,{onClick:handleLinkClick}),children);};exports.Link = Link;var Router=(function(_Component){_inherits(Router,_Component);function Router(){_classCallCheck(this,Router);_Component.apply(this,arguments);}Router.prototype.getInitialState = function getInitialState(){return {url:getCurrentUrl()};};Router.prototype.routeTo = function routeTo(url){this.setState({url:url});};Router.prototype.componentWillMount = function componentWillMount(){routers.push(this);};Router.prototype.componentWillUnmount = function componentWillUnmount(){routers.splice(routers.indexOf(this),1);};Router.prototype.render = function render(_ref2,_ref3){var children=_ref2.children;var onChange=_ref2.onChange;var url=_ref3.url;var active=children.filter(function(_ref4){var attributes=_ref4.attributes;var path=attributes.path,matches=exec(url,path);if(matches){attributes.url = url;attributes.matches = matches;for(var i in matches) {if(matches.hasOwnProperty(i)){attributes[i] = matches[i];}}return true;}});var previous=this.previousUrl;if(url !== previous){this.previousUrl = url;if(typeof onChange === 'function'){onChange({router:this,url:url,previous:previous,active:active,current:active[0]});}}return active[0] || null;};return Router;})(_preact.Component);exports.Router = Router;var Route=function Route(_ref5){var RoutedComponent=_ref5.component;var url=_ref5.url;var matches=_ref5.matches;return _preact.h(RoutedComponent,{url:url,matches:matches});};exports.Route = Route;function exec(url,route){var reg=/(?:\?([^#]*))?(#.*)?$/,c=url.match(reg),matches={};if(c && c[1]){var p=c[1].split('&');for(var i=0;i < p.length;i++) {var r=p[i].split('=');matches[decodeURIComponent(r[0])] = decodeURIComponent(r.slice(1).join('='));}}url = segmentize(url.replace(reg,''));route = segmentize(route);var max=Math.max(url.length,route.length);for(var i=0;i < max;i++) {if(route[i] && route[i].charAt(0) === ':'){matches[route[i].substring(1)] = decodeURIComponent(url[i] || '');}else {if(route[i] !== url[i]){return false;}}}return matches;}Router.route = route;Router.Route = Route;Router.Link = Link;exports['default'] = Router;var segmentize=function segmentize(url){return strip(url).split('/');};var strip=function strip(url){return url.replace(/(^\/+|\/+$)/g,'');};});
(function(global,factory){if(typeof define === 'function' && define.amd){define(['exports','preact'],factory);}else if(typeof exports !== 'undefined'){factory(exports,require('preact'));}else {var mod={exports:{}};factory(mod.exports,global.preact);global.preactRouter = mod.exports;}})(this,function(exports,_preact){'use strict';exports.__esModule = true;var _extends=Object.assign || function(target){for(var i=1;i < arguments.length;i++) {var source=arguments[i];for(var key in source) {if(Object.prototype.hasOwnProperty.call(source,key)){target[key] = source[key];}}}return target;};exports.route = route;function _objectWithoutProperties(obj,keys){var target={};for(var i in obj) {if(keys.indexOf(i) >= 0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i] = obj[i];}return target;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function');}}function _inherits(subClass,superClass){if(typeof superClass !== 'function' && superClass !== null){throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var routers=[];function route(url){var replace=arguments.length <= 1 || arguments[1] === undefined?false:arguments[1];if(typeof url !== 'string' && url.url){replace = url.replace;url = url.url;}if(history){if(replace === true){history.replaceState(null,null,url);}else {history.pushState(null,null,url);}}routeTo(url);}function routeTo(url){routers.forEach(function(router){return router.routeTo(url);});}function getCurrentUrl(){return '' + (location.pathname || '') + (location.search || '');}if(typeof addEventListener === 'function'){addEventListener('popstate',function(){return routeTo(getCurrentUrl());});}function handleLinkClick(e){route(this.getAttribute('href'));if(e.stopImmediatePropagation)e.stopImmediatePropagation();e.stopPropagation();e.preventDefault();return false;}var Link=function Link(_ref){var children=_ref.children;var props=_objectWithoutProperties(_ref,['children']);return _preact.h('a',_extends({},props,{onClick:handleLinkClick}),children);};exports.Link = Link;var Router=(function(_Component){_inherits(Router,_Component);function Router(){_classCallCheck(this,Router);_Component.apply(this,arguments);}Router.prototype.getInitialState = function getInitialState(){return {url:getCurrentUrl()};};Router.prototype.routeTo = function routeTo(url){this.setState({url:url});};Router.prototype.componentWillMount = function componentWillMount(){routers.push(this);};Router.prototype.componentWillUnmount = function componentWillUnmount(){routers.splice(routers.indexOf(this),1);};Router.prototype.render = function render(_ref2,_ref3){var children=_ref2.children;var onChange=_ref2.onChange;var url=_ref3.url;var active=children.filter(function(_ref4){var attributes=_ref4.attributes;var path=attributes.path,matches=exec(url,path);if(matches){attributes.url = url;attributes.matches = matches;for(var i in matches) {if(matches.hasOwnProperty(i)){attributes[i] = matches[i];}}return true;}});var previous=this.previousUrl;if(url !== previous){this.previousUrl = url;if(typeof onChange === 'function'){onChange({router:this,url:url,previous:previous,active:active,current:active[0]});}}return active[0] || null;};return Router;})(_preact.Component);exports.Router = Router;var Route=function Route(_ref5){var RoutedComponent=_ref5.component;var url=_ref5.url;var matches=_ref5.matches;return _preact.h(RoutedComponent,{url:url,matches:matches});};exports.Route = Route;function exec(url,route){var reg=/(?:\?([^#]*))?(#.*)?$/,c=url.match(reg),matches={};if(c && c[1]){var p=c[1].split('&');for(var i=0;i < p.length;i++) {var r=p[i].split('=');matches[decodeURIComponent(r[0])] = decodeURIComponent(r.slice(1).join('='));}}url = segmentize(url.replace(reg,''));route = segmentize(route);var max=Math.max(url.length,route.length);for(var i=0;i < max;i++) {if(route[i] && route[i].charAt(0) === ':'){matches[route[i].substring(1)] = decodeURIComponent(url[i] || '');}else {if(route[i] !== url[i]){return false;}}}return matches;}Router.route = route;Router.Route = Route;Router.Link = Link;exports['default'] = Router;var segmentize=function segmentize(url){return strip(url).split('/');};var strip=function strip(url){return url.replace(/(^\/+|\/+$)/g,'');};});
//# sourceMappingURL=preact-router.js.map
{
"name": "preact-router",
"version": "1.0.0",
"version": "1.1.0",
"description": "Connect your components up to that address bar.",

@@ -5,0 +5,0 @@ "main": "dist/preact-router.js",

@@ -5,5 +5,14 @@ import { h, Component } from 'preact';

export function route(url) {
export function route(url, replace=false) {
if (typeof url!=='string' && url.url) {
replace = url.replace;
url = url.url;
}
if (history) {
history.pushState(null, null, url);
if (replace===true) {
history.replaceState(null, null, url);
}
else {
history.pushState(null, null, url);
}
}

@@ -10,0 +19,0 @@ routeTo(url);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc