Как я могу получить доступ к props.location в шаблоне маршрута в react-static с react-router?
Я очень новичок в реагирующей статике и пытаюсь адаптировать существующее приложение реагирующего маршрутизатора для его использования. У меня есть мой
static.config.js
настроить как:
export default {
getRoutes: async ({ dev }) => {
return [
{
path: '/details/someobject',
template: 'src/containers/ObjectDetailPage',
},
{
path: '/',
template: 'src/containers/HomePage',
}
];
},
entry: 'index-react-static.js',
plugins: [
'react-static-plugin-react-router'
]
}
А потом
index-react-static.js
идентичен шаблону из
react-static create
:
import React from 'react'
import ReactDOM from 'react-dom'
import { AppContainer } from 'react-hot-loader'
// Your top level component
import AppReactStatic from './AppReactStatic'
// Export your top level component as JSX (for static rendering)
export default AppReactStatic
// Render your app
if (typeof document !== 'undefined') {
const target = document.getElementById('root')
const renderMethod = target.hasChildNodes()
? ReactDOM.hydrate
: ReactDOM.render
const render = Comp => {
renderMethod(
<AppContainer>
<Comp />
</AppContainer>,
target
)
}
// Render!
render(AppReactStatic)
// Hot Module Replacement
if (module && module.hot) {
module.hot.accept('./AppReactStatic', () => {
render(App)
})
}
}
А потом
AppReactStatic.js
в качестве:
import React from 'react'
import { Root, Routes } from 'react-static'
import { Provider } from 'react-redux';
import store from './store/store'
function AppReactStatic() {
return (
<Root>
<Provider store={ store }>
<React.Suspense fallback={<span>Loading...</span>}>
<Routes />
</React.Suspense>
</Provider>
</Root>
)
}
export default AppReactStatic
Но реквизит, который
ObjectDetailPage
получает не включает
location
(или же
history
или же
match
). Что мне не хватает в моей настройке?
Трассировка стека для моей ошибки, похоже, указывает
withRouter
обертывает мой компонент:
in Route (created by withRouter())
in withRouter()
in Unknown (created by Routes)
in Routes (created by AppReactStatic)