-
Notifications
You must be signed in to change notification settings - Fork 62
Closed
Description
Hi, there.
I have next usage question.
Before import module I need to fetch API service to resolve what module I have to import. My application uses SEO-friendly routing. For example:
- URL
/my-very-nice-article
correspondsArticlePage
component - URL
/statistics-for-my-other-very-nice-article
correspondsArticleStatisticsPage
and etc.
All matches between URLs and components are stored in database.
So in resolve function of my async component I need to get current location from props
(I use react-router v4
).
All my routing consists of the next line:
<Route path="*" component={AsyncComponentResolver}/>
I didn't find any information how to use props
in resolve
function and write wrapper component:
class AsyncComponentResolver extends Component {
render(){
const {pathname} = this.props.location;
const AsyncComponent = asyncComponent({
resolve: () => {
return API.fetchRouteInformation(pathname)
.then(({modulePath}) => import(modulePath))
},
LoadingComponent: ({ match }) => <div>Resolving {match.url}</div>
});
return <AsyncComponent {...this.props}/>
}
}
But this solution doesn't work in stage of server-side rendering and I have <div>Resolving /my-very-nice-article</div>
in rendered HTML instead of rendered ArticlePage
component.
Thanks! It will be very nice if you show me the right way.
Metadata
Metadata
Assignees
Labels
No labels