File tree 3 files changed +14
-6
lines changed
3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 13
13
"react" : " ^16.4.1" ,
14
14
"react-dom" : " ^16.4.1" ,
15
15
"react-redux" : " ^5.0.7" ,
16
+ "react-router-dom" : " ^4.3.1" ,
16
17
"redux" : " ^4.0.0" ,
17
18
"styled-components" : " ^3.4.9"
18
19
},
21
22
"@types/react" : " ^16.4.1" ,
22
23
"@types/react-dom" : " ^16.0.6" ,
23
24
"@types/react-redux" : " ^6.0.2" ,
25
+ "@types/react-router-dom" : " ^4.3.1" ,
24
26
"ts-loader" : " ^4.4.1" ,
25
27
"typescript" : " ^2.9.2" ,
26
28
"webpack" : " ^4.12.1" ,
Original file line number Diff line number Diff line change @@ -2,20 +2,23 @@ import * as React from "react";
2
2
import * as ReactDOM from "react-dom" ;
3
3
import * as Redux from "redux" ;
4
4
import * as ReactRedux from "react-redux" ;
5
+ import { BrowserRouter as Router } from "react-router-dom" ;
5
6
6
7
import App from "common/App" ;
7
8
import { changeTitle } from "common/redux/reducer/title" ;
8
9
9
10
//@ts -ignore
10
- const preloadedState = window [ "PRELOADED_STATE " ] ;
11
+ const preloadedState = window [ "__PRELOADED_STATE__ " ] ;
11
12
//@ts -ignore
12
- delete window [ "PRELOADED_STATE " ] ;
13
+ delete window [ "__PRELOADED_STATE__ " ] ;
13
14
14
15
const store = Redux . createStore ( changeTitle , preloadedState )
15
16
16
17
ReactDOM . hydrate (
17
18
< ReactRedux . Provider store = { store } >
18
- < App />
19
+ < Router >
20
+ < App />
21
+ </ Router >
19
22
</ ReactRedux . Provider > ,
20
23
document . getElementById ( "root" )
21
24
) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import * as Express from "express";
4
4
import * as Redux from "redux" ;
5
5
import * as ReactRedux from "react-redux" ;
6
6
import { ServerStyleSheet } from "styled-components" ;
7
+ import { StaticRouter as Router } from "react-router-dom" ;
7
8
8
9
import App from "common/App" ;
9
10
import { changeTitle } from "common/redux/reducer/title" ;
@@ -16,12 +17,14 @@ function main() {
16
17
17
18
express . use ( Express . static ( "build" ) ) ;
18
19
19
- express . get ( "/" , ( req , res , next ) => {
20
+ express . get ( "/* " , ( req , res , next ) => {
20
21
21
22
const sheet = new ServerStyleSheet ( )
22
23
const html = ReactDOM . renderToString ( sheet . collectStyles (
23
24
< ReactRedux . Provider store = { store } >
24
- < App />
25
+ < Router location = { req . path } context = { { } } >
26
+ < App />
27
+ </ Router >
25
28
</ ReactRedux . Provider >
26
29
) ) ;
27
30
@@ -39,7 +42,7 @@ function main() {
39
42
<body>
40
43
<div id="root">${ html } </div>
41
44
<script>
42
- window["PRELOADED_STATE "] = ${ preloadedState }
45
+ window["__PRELOADED_STATE__ "] = ${ preloadedState }
43
46
</script>
44
47
<script type="application/javascript" src="bundle.js"></script>
45
48
${ styleTags }
You can’t perform that action at this time.
0 commit comments