1
我有這樣我的服務器反應路由器 - 服務器端渲染比賽
app.get('*', function(req, res) {
match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
const body = renderToString(<RouterContext {...renderProps} />)
res.send(`
<!DOCTYPE html>
<html>
<head>
<link href="//cdn.muicss.com/mui-0.6.5/css/mui.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="root">${body}</div>
<script defer src="assets/app.js"></script>
</body>
</html>
`)
})
})
在這在客戶端
import { Router, hashHistory, browserHistory, match } from 'react-router'
let history = browserHistory
//client side, will become app.js
match({ routes, location, history }, (error, redirectLocation, renderProps) => {
render(<Router {...renderProps} />, document.getElementById('root'))
})
問題 它的工作原理,只有當我刪除了( let history = browserHistory),但它將/#/ hash前綴添加到我的url(我不想發生這種情況)。
當我離開設(歷史= browserHistory)那裏,它拋出一個錯誤
警告:反應試圖重複使用的容器標記,但校驗和無效。這通常意味着您正在使用服務器渲染,並且服務器上生成的標記不是客戶期望的。 React注入了新的標記來補償哪些作品,但是你已經失去了許多服務器渲染的好處。相反,請找出爲什麼客戶端或服務器上生成的標記不同: (客戶端)<! - 反應空:1 - (服務器)<部分數據reactro
的錯誤信息是很清楚,不過,我不明白爲什麼它的工作原理與hashHistory但未能與browserHistory