【发布时间】:2017-05-21 18:03:57
【问题描述】:
我正在按照此处给出的示例使用反应路由器服务器端:
https://github.com/ReactTraining/react-router/blob/v2.8.1/docs/guides/ServerRendering.md
不知何故,与这个简单的路由器设置匹配不匹配给定的位置:
import React from "react"
import ReactDOMServer from 'react-dom/server'
import { Route, match, RouterContext, IndexRoute } from 'react-router'
const sampleRoutes = (
<Route path="/">
<IndexRoute component={() => <span>index</span>}/>
<Route path="z1" component={() => <span>z1</span>} />
<Route path="z2" component={() => <span>z2</span>} />
</Route>
)
const render = location => {
match({sampleRoutes, location}, (error, redirectLocation, renderProps) => {
if (error) {
console.error("error: "+ error)
} else if (redirectLocation) {
console.error("redirect to " + redirectLocation)
} else if (renderProps) {
var page = ReactDOMServer.renderToStaticMarkup(<RouterContext {...renderProps} />)
console.log(page)
} else {
console.error("location nof found: '"+ location +"'")
}
})
}
render("/z1")
我在控制台上收到“找不到路由 /z1”。
【问题讨论】:
标签: react-router