在服务器端呈现期间无法在react组件的props中看到staticContext

时间:2018-06-11 16:56:41

标签: reactjs react-router serverside-rendering

我是服务器端渲染应用程序,服务器代码看起来像这样

const markup = renderToString(
<StaticRouter context={{a:1}} location={req.url}>
<App d='8' />
</StaticRouter>
)

并在App组件中打印出道具

class App extends Component {
constructor(props){
super(props);
console.log(this)
}

但是输出没有staticContext,它看起来像这样

App {
props: { d: '8' },
context: undefined,
refs: {},
updater:
 { isMounted: [Function: isMounted],
 enqueueForceUpdate: [Function: enqueueForceUpdate],
 enqueueReplaceState: [Function: enqueueReplaceState],
 enqueueSetState: [Function: enqueueSetState] } }

我正在使用react 16.3和react-router-dom 4.3.1,为什么我无法访问staticContext prop?

0 个答案:

没有答案