Socket
Socket
Sign inDemoInstall

react-router

Package Overview
Dependencies
Maintainers
2
Versions
518
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-router - npm Package Compare versions

Comparing version 0.12.1 to 0.12.2

20

lib/createRouter.js

@@ -64,2 +64,17 @@ "use strict";

function addRoutesToNamedRoutes(routes, namedRoutes) {
var route;
for (var i = 0, len = routes.length; i < len; ++i) {
route = routes[i];
if (route.name) {
invariant(namedRoutes[route.name] == null, "You may not have more than one route named \"%s\"", route.name);
namedRoutes[route.name] = route;
}
if (route.childRoutes) addRoutesToNamedRoutes(route.childRoutes, namedRoutes);
}
}
/**

@@ -125,2 +140,3 @@ * Creates and returns a new router using the given options. A router

this.cancelPendingTransition();
this.namedRoutes = {};
this.routes = [];

@@ -135,2 +151,4 @@ },

addRoutesToNamedRoutes(routes, this.namedRoutes);
this.routes.push.apply(this.routes, routes);

@@ -166,3 +184,3 @@ },

} else {
var route = to instanceof Route ? to : Route.findRouteByName(this.routes, to);
var route = to instanceof Route ? to : this.namedRoutes[to];

@@ -169,0 +187,0 @@ invariant(route instanceof Route, "Cannot find a route named \"%s\"", to);

79

lib/Route.js

@@ -20,84 +20,21 @@ "use strict";

Route.prototype.toString = function () {
var string = "<Route";
if (this.name) string += " name=\"" + this.name + "\"";
string += " path=\"" + this.path + "\">";
return string;
};
/**
* Appends the given route to this route's child routes.
*/
Route.prototype.appendChildRoute = function (route) {
invariant(route instanceof Route, "route.appendChildRoute must use a valid Route");
Route.prototype.appendChild = function (route) {
invariant(route instanceof Route, "route.appendChild must use a valid Route");
if (!this.childRoutes) this.childRoutes = [];
if (route.name) {
invariant(this.childRoutes.every(function (childRoute) {
return childRoute.name !== route.name;
}), "Route %s may not have more than one child route named \"%s\"", this, route.name);
}
this.childRoutes.push(route);
};
/**
* Allows looking up a child route using a "." delimited string, e.g.:
*
* route.appendChildRoute(
* Router.createRoute({ name: 'user' }, function () {
* Router.createRoute({ name: 'new' });
* })
* );
*
* var NewUserRoute = route.lookupChildRoute('user.new');
*
* See also Route.findRouteByName.
*/
Route.prototype.lookupChildRoute = function (names) {
if (!this.childRoutes) return null;
Route.prototype.toString = function () {
var string = "<Route";
return Route.findRouteByName(this.childRoutes, names);
};
if (this.name) string += " name=\"" + this.name + "\"";
/**
* Searches the given array of routes and returns the route that matches
* the given name. The name should be a . delimited string like "user.new"
* that specifies the names of nested routes. Routes in the hierarchy that
* do not have a name do not need to be specified in the search string.
*
* var routes = [
* Router.createRoute({ name: 'user' }, function () {
* Router.createRoute({ name: 'new' });
* })
* ];
*
* var NewUserRoute = Route.findRouteByName(routes, 'user.new');
*/
Route.findRouteByName = function (routes, names) {
if (typeof names === "string") names = names.split(".");
string += " path=\"" + this.path + "\">";
var route, foundRoute;
for (var i = 0, len = routes.length; i < len; ++i) {
route = routes[i];
if (route.name === names[0]) {
if (names.length === 1) return route;
if (!route.childRoutes) return null;
return Route.findRouteByName(route.childRoutes, names.slice(1));
} else if (route.name == null) {
// Transparently skip over unnamed routes in the tree.
foundRoute = route.lookupChildRoute(names);
if (foundRoute != null) return foundRoute;
}
}
return null;
return string;
};

@@ -189,3 +126,3 @@

parentRoute.appendChildRoute(route);
parentRoute.appendChild(route);
}

@@ -192,0 +129,0 @@

{
"name": "react-router",
"version": "0.12.1",
"version": "0.12.2",
"description": "A complete routing library for React.js",

@@ -5,0 +5,0 @@ "main": "lib",

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