Skip to content

Commit 686f44b

Browse files
committed
Add npm build
1 parent 83328a0 commit 686f44b

39 files changed

+2718
-0
lines changed

build/npm/README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
[![npm package](https://img.shields.io/npm/v/react-router.svg?style=flat-square)](https://www.npmjs.org/package/react-router)
2+
[![build status](https://img.shields.io/travis/rackt/react-router/master.svg?style=flat-square)](https://travis-ci.org/rackt/react-router)
3+
[![dependency status](https://img.shields.io/david/rackt/react-router.svg?style=flat-square)](https://david-dm.org/rackt/react-router)
4+
5+
React Router
6+
============
7+
8+
A complete routing library for React.
9+
10+
Docs
11+
----
12+
13+
- [Guide: Overview](/docs/guides/overview.md)
14+
- [API](/docs/api/)
15+
16+
Important Notes
17+
---------------
18+
19+
### SemVer
20+
21+
Before our `1.0` release, breaking API changes will cause a bump to
22+
`0.x`. For example, `0.4.1` and `0.4.8` will have the same API, but
23+
`0.5.0` will have breaking changes.
24+
25+
Please refer to the [upgrade guide](/UPGRADE_GUIDE.md) and
26+
[changelog](/CHANGELOG.md) when upgrading.
27+
28+
Installation
29+
------------
30+
31+
```sh
32+
npm install react-router
33+
# or
34+
bower install react-router
35+
```
36+
37+
This library is written with CommonJS modules. If you are using
38+
browserify, webpack, or similar, you can consume it like anything else
39+
installed from npm.
40+
41+
There is also a global build available on bower, find the library on
42+
`window.ReactRouter`.
43+
44+
The library is also available on the popular CDN [cdnjs](https://cdnjs.com/libraries/react-router).
45+
46+
Features
47+
--------
48+
49+
- Nested views mapped to nested routes
50+
- Modular construction of route hierarchy
51+
- Sync and async transition hooks
52+
- Transition abort / redirect / retry
53+
- Dynamic segments
54+
- Query parameters
55+
- Links with automatic `.active` class when their route is active
56+
- Multiple root routes
57+
- Hash or HTML5 history (with fallback) URLs
58+
- Declarative Redirect routes
59+
- Declarative NotFound routes
60+
- Browser scroll behavior with transitions
61+
62+
Check out the `examples` directory to see how simple previously complex UI
63+
and workflows are to create.
64+
65+
What's it look like?
66+
--------------------
67+
68+
```js
69+
var routes = (
70+
<Route handler={App} path="/">
71+
<DefaultRoute handler={Home} />
72+
<Route name="about" handler={About} />
73+
<Route name="users" handler={Users}>
74+
<Route name="recent-users" path="recent" handler={RecentUsers} />
75+
<Route name="user" path="/user/:userId" handler={User} />
76+
<NotFoundRoute handler={UserRouteNotFound}/>
77+
</Route>
78+
<NotFoundRoute handler={NotFound}/>
79+
<Redirect from="company" to="about" />
80+
</Route>
81+
);
82+
83+
Router.run(routes, function (Handler) {
84+
React.render(<Handler/>, document.body);
85+
});
86+
87+
// Or, if you'd like to use the HTML5 history API for cleaner URLs:
88+
89+
Router.run(routes, Router.HistoryLocation, function (Handler) {
90+
React.render(<Handler/>, document.body);
91+
});
92+
```
93+
94+
See more in the [overview guide](/docs/guides/overview.md).
95+
96+
Benefits of this Approach
97+
-------------------------
98+
99+
1. **Incredible screen-creation productivity** - There is only one
100+
use-case when a user visits a route: render something. Every user
101+
interface has layers (or nesting) whether it's a simple navbar or
102+
multiple levels of master-detail. Coupling nested routes to these
103+
nested views gets rid of a ton of work for the developer to wire all
104+
of it together when the user switches routes. Adding new screens
105+
could not get faster.
106+
107+
2. **Immediate understanding of application structure** - When routes
108+
are declared in one place, developers can easily construct a mental
109+
image of the application. It's essentially a sitemap. There's not a
110+
better way to get so much information about your app this quickly.
111+
112+
3. **Code tractability** - When a developer gets a ticket to fix a bug
113+
at as specific url they simply 1) look at the route config, then 2)
114+
go find the handler for that route. Every entry point into your
115+
application is represented by these routes.
116+
117+
4. **URLs are your first thought, not an after-thought** - With React
118+
Router, you don't get UI on the page without configuring a url first.
119+
Fortunately, it's wildly productive this way, too.
120+
121+
Related Modules
122+
---------------
123+
124+
- [rnr-constrained-route](https://github.com/bjyoungblood/rnr-constrained-route) - validate paths
125+
and parameters on route handlers.
126+
- [react-router-bootstrap](https://github.com/mtscout6/react-router-bootstrap) - Integration with [react-bootstrap](https://github.com/react-bootstrap/react-bootstrap) components.
127+
128+
Contributing
129+
------------
130+
131+
Please see [CONTRIBUTING](CONTRIBUTING.md)
132+
133+
Thanks, Ember
134+
-------------
135+
136+
This library is highly inspired by the Ember.js routing API. In general,
137+
it's a translation of the Ember router api to React. Huge thanks to the
138+
Ember team for solving the hardest part already.
139+

build/npm/lib/Cancellation.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
/**
4+
* Represents a cancellation caused by navigating away
5+
* before the previous transition has fully resolved.
6+
*/
7+
function Cancellation() {}
8+
9+
module.exports = Cancellation;

build/npm/lib/Configuration.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use strict";
2+
3+
var warning = require("react/lib/warning");
4+
var invariant = require("react/lib/invariant");
5+
6+
function checkPropTypes(componentName, propTypes, props) {
7+
for (var propName in propTypes) {
8+
if (propTypes.hasOwnProperty(propName)) {
9+
var error = propTypes[propName](props, propName, componentName);
10+
11+
if (error instanceof Error) warning(false, error.message);
12+
}
13+
}
14+
}
15+
16+
var Configuration = {
17+
18+
statics: {
19+
20+
validateProps: function validateProps(props) {
21+
checkPropTypes(this.displayName, this.propTypes, props);
22+
}
23+
24+
},
25+
26+
render: function render() {
27+
invariant(false, "%s elements are for router configuration only and should not be rendered", this.constructor.displayName);
28+
}
29+
30+
};
31+
32+
module.exports = Configuration;

build/npm/lib/History.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
3+
var invariant = require("react/lib/invariant");
4+
var canUseDOM = require("react/lib/ExecutionEnvironment").canUseDOM;
5+
6+
var History = {
7+
8+
/**
9+
* The current number of entries in the history.
10+
*
11+
* Note: This property is read-only.
12+
*/
13+
length: 1,
14+
15+
/**
16+
* Sends the browser back one entry in the history.
17+
*/
18+
back: function back() {
19+
invariant(canUseDOM, "Cannot use History.back without a DOM");
20+
21+
// Do this first so that History.length will
22+
// be accurate in location change listeners.
23+
History.length -= 1;
24+
25+
window.history.back();
26+
}
27+
28+
};
29+
30+
module.exports = History;

build/npm/lib/Match.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"use strict";
2+
3+
/* jshint -W084 */
4+
5+
var Path = require("./utils/Path");
6+
7+
function Match(pathname, params, query, routes) {
8+
this.pathname = pathname;
9+
this.params = params;
10+
this.query = query;
11+
this.routes = routes;
12+
}
13+
14+
function deepSearch(route, pathname, query) {
15+
// Check the subtree first to find the most deeply-nested match.
16+
var childRoutes = route.childRoutes;
17+
if (childRoutes) {
18+
var match, childRoute;
19+
for (var i = 0, len = childRoutes.length; i < len; ++i) {
20+
childRoute = childRoutes[i];
21+
22+
if (childRoute.isDefault || childRoute.isNotFound) continue; // Check these in order later.
23+
24+
if (match = deepSearch(childRoute, pathname, query)) {
25+
// A route in the subtree matched! Add this route and we're done.
26+
match.routes.unshift(route);
27+
return match;
28+
}
29+
}
30+
}
31+
32+
// No child routes matched; try the default route.
33+
var defaultRoute = route.defaultRoute;
34+
if (defaultRoute && (params = Path.extractParams(defaultRoute.path, pathname))) {
35+
return new Match(pathname, params, query, [route, defaultRoute]);
36+
} // Does the "not found" route match?
37+
var notFoundRoute = route.notFoundRoute;
38+
if (notFoundRoute && (params = Path.extractParams(notFoundRoute.path, pathname))) {
39+
return new Match(pathname, params, query, [route, notFoundRoute]);
40+
} // Last attempt: check this route.
41+
var params = Path.extractParams(route.path, pathname);
42+
if (params) {
43+
return new Match(pathname, params, query, [route]);
44+
}return null;
45+
}
46+
47+
/**
48+
* Attempts to match depth-first a route in the given route's
49+
* subtree against the given path and returns the match if it
50+
* succeeds, null if no match can be made.
51+
*/
52+
Match.findMatchForPath = function (routes, path) {
53+
var pathname = Path.withoutQuery(path);
54+
var query = Path.extractQuery(path);
55+
var match = null;
56+
57+
for (var i = 0, len = routes.length; match == null && i < len; ++i) match = deepSearch(routes[i], pathname, query);
58+
59+
return match;
60+
};
61+
62+
module.exports = Match;

build/npm/lib/Navigation.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"use strict";
2+
3+
var PropTypes = require("./PropTypes");
4+
5+
/**
6+
* A mixin for components that modify the URL.
7+
*
8+
* Example:
9+
*
10+
* var MyLink = React.createClass({
11+
* mixins: [ Router.Navigation ],
12+
* handleClick: function (event) {
13+
* event.preventDefault();
14+
* this.transitionTo('aRoute', { the: 'params' }, { the: 'query' });
15+
* },
16+
* render: function () {
17+
* return (
18+
* <a onClick={this.handleClick}>Click me!</a>
19+
* );
20+
* }
21+
* });
22+
*/
23+
var Navigation = {
24+
25+
contextTypes: {
26+
makePath: PropTypes.func.isRequired,
27+
makeHref: PropTypes.func.isRequired,
28+
transitionTo: PropTypes.func.isRequired,
29+
replaceWith: PropTypes.func.isRequired,
30+
goBack: PropTypes.func.isRequired
31+
},
32+
33+
/**
34+
* Returns an absolute URL path created from the given route
35+
* name, URL parameters, and query values.
36+
*/
37+
makePath: function makePath(to, params, query) {
38+
return this.context.makePath(to, params, query);
39+
},
40+
41+
/**
42+
* Returns a string that may safely be used as the href of a
43+
* link to the route with the given name.
44+
*/
45+
makeHref: function makeHref(to, params, query) {
46+
return this.context.makeHref(to, params, query);
47+
},
48+
49+
/**
50+
* Transitions to the URL specified in the arguments by pushing
51+
* a new URL onto the history stack.
52+
*/
53+
transitionTo: function transitionTo(to, params, query) {
54+
this.context.transitionTo(to, params, query);
55+
},
56+
57+
/**
58+
* Transitions to the URL specified in the arguments by replacing
59+
* the current URL in the history stack.
60+
*/
61+
replaceWith: function replaceWith(to, params, query) {
62+
this.context.replaceWith(to, params, query);
63+
},
64+
65+
/**
66+
* Transitions to the previous URL.
67+
*/
68+
goBack: function goBack() {
69+
return this.context.goBack();
70+
}
71+
72+
};
73+
74+
module.exports = Navigation;

build/npm/lib/NavigationContext.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
3+
var PropTypes = require("./PropTypes");
4+
5+
/**
6+
* Provides the router with context for Router.Navigation.
7+
*/
8+
var NavigationContext = {
9+
10+
childContextTypes: {
11+
makePath: PropTypes.func.isRequired,
12+
makeHref: PropTypes.func.isRequired,
13+
transitionTo: PropTypes.func.isRequired,
14+
replaceWith: PropTypes.func.isRequired,
15+
goBack: PropTypes.func.isRequired
16+
},
17+
18+
getChildContext: function getChildContext() {
19+
return {
20+
makePath: this.constructor.makePath.bind(this.constructor),
21+
makeHref: this.constructor.makeHref.bind(this.constructor),
22+
transitionTo: this.constructor.transitionTo.bind(this.constructor),
23+
replaceWith: this.constructor.replaceWith.bind(this.constructor),
24+
goBack: this.constructor.goBack.bind(this.constructor)
25+
};
26+
}
27+
28+
};
29+
30+
module.exports = NavigationContext;

0 commit comments

Comments
 (0)