Here's an example from the docs.は、サーバとレンダリングルーターサーバーに反応私はこのようなオブジェクトを持って
import { renderToString } from 'react-dom/server'
import { match, RouterContext } from 'react-router'
import routes from './routes'
serve((req, res) => {
// Note that req.url here should be the full URL path from
// the original request, including the query string.
match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
if (error) {
res.status(500).send(error.message)
} else if (redirectLocation) {
res.redirect(302, redirectLocation.pathname + redirectLocation.search)
} else if (renderProps) {
// You can also check renderProps.components or renderProps.routes for
// your "not found" component or route respectively, and send a 404 as
// below, if you're using a catch-all route.
res.status(200).send(renderToString(<RouterContext {...renderProps} />))
} else {
res.status(404).send('Not found')
}
})
})
小道具:
let reactServerProps = {
'gaKey': process.env.GA_KEY,
'query': req.query,
}
私はここにルータを反応
res.status(200).send(renderToString(<RouterContext {...renderProps} {...reactServerProps} />))
にこのオブジェクトを渡すためにしようとしています
そして、私は自分のコンポーネント内の変数にアクセスできないようです。
私はすでに私のすべてのコンポーネント変数を探し 'props'名前空間を使って配線されています。データを 'props'として渡す方法はありますか? – ThomasReggi
createElementメソッドでクラックを取ることができました。ここに実装が見つかりました:http://stackoverflow.com/questions/33978781再び、私は反応ルータv1以来働いているとは思えません。 私はそれがオブジェクトを使用するために、かなりハック感じても、それは、も可能だと思います '' renderProps'に直接データを注入するために() 'メソッドを割り当てます。つまり、(renderProps.params、reactServerProps)を割り当てます。 –
@ThomasReggi良いニュースは、文脈ではなくすべての子どもたちに小道具として値を渡すことはまだ完全に実行可能なようです。説明する答えを更新しました。 –