forked from ramsaylanier/WordExpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
56 lines (47 loc) · 1.05 KB
/
routes.js
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
import React from 'react';
import Relay from 'react-relay';
import { IndexRoute, Route } from 'react-router';
import App from './App.js';
import PostSingle from './components/posts/PostSingle.js';
import Layouts from './components/layouts/layouts.js';
const AppQueries = {
viewer: () => Relay.QL`
query {
viewer
}
`,
};
function setLayout(nextState, replaceState){
const { pathname } = nextState.location;
const { page } = nextState.params;
let Layout;
if ( pathname == '/' ){
Layout = Layouts['FrontPage'];
} else {
Layout = Layouts[page] ? Layouts[page] : Layouts['Default'];
}
this.layout = Layout;
this.component = Layout.Component;
}
let routes = (
<Route
path="/" component={App}
queries={AppQueries}
>
<IndexRoute
onEnter={setLayout}
queries={AppQueries}
/>
<Route
path=":page"
onEnter={setLayout}
queries={AppQueries}
/>
<Route
path="post/:post"
component={PostSingle}
queries={AppQueries}
/>
</Route>
);
export default routes;