aspirisen
aspirisen

Reputation: 1025

How to add spinner while async routes are loading?

React Router can load routes asynchronously via getComponent or getComponents and it is ok. But if user has slow internet connection i should show some page with loader and some text message like 'Please wait component is loading' and so on. How to configure that using getComponent?

Upvotes: 0

Views: 1209

Answers (1)

Paul S
Paul S

Reputation: 36787

Instead of getComponent, you should use component and provide it a component that shows a loading message by default, but once it has loaded a component it shows that component instead.

You can reference this github gist for an example. It was written for React Router v4, but the idea is the same. Instead of rendering null you would reference the spinner, loader message, etc.

Upvotes: 2

Related Questions