-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathRouter.js
More file actions
69 lines (51 loc) · 1.47 KB
/
Router.js
File metadata and controls
69 lines (51 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"use strict";
var React = require('react');
var Preloaded = require('react-async/lib/Preloaded');
var RoutingEnvironmentMixin = require('./RoutingEnvironmentMixin');
var matchRoutes = require('./matchRoutes');
/**
* A router has two responsibilities:
*
* 1. to determine whether it has a match for a particular path
* 2. to render contents for the current path
*/
var RouterMixin = {
mixins: [RoutingEnvironmentMixin],
match: function(path) {
path = path || this.getPath();
return matchRoutes(this.props.children, path);
},
getRendered: function() {
if (this.refs.rendered) {
return this.refs.rendered.getRendered();
}
},
hasPendingUpdate: function() {
return this.refs.rendered && this.refs.rendered.hasPendingUpdate();
},
render: function() {
var handler = this.match(this.getPath()).createHandler();
if (handler) {
handler = Preloaded({ref: 'rendered'}, handler);
}
return this.transferPropsTo(this.props.component(null, handler));
}
};
var Locations = React.createClass({
mixins: [RouterMixin],
displayName: 'Locations',
getDefaultProps: function() {
return {component: React.DOM.div};
}
});
var Pages = React.createClass({
mixins: [RouterMixin],
displayName: 'Pages',
getDefaultProps: function() {
return {component: React.DOM.body};
}
});
module.exports = {
Locations: Locations,
Pages: Pages
}