如何对悬念做出反应-LazyLoading

时间:2019-08-31 22:02:06

标签: javascript reactjs redux react-router

如何使Reacts Suspense不显示任何后备,而是停留在同一页面上 这就是我所拥有的

return (
      <Router>
        <Provider store={store}>
          <Fragment>
            <Switch>
              <Layout>
                <Suspense fallback={<BusyIndicator />} maxDuration={5000}>
                  <PrivateRoute
                    exact
                    path="/en/account/dashboard"
                    component={Home}
                  />
                  <PrivateRoute exact path="/en/books" component={Books} />
                  <PrivateRoute
                    exact
                    path="/en/account/quiz"
                    component={Quiz}
                  />

                  <PrivateRoute
                    exact
                    path="/en/account/quiz/:slug"
                    component={QuizDetail}
                  />
                  <PrivateRoute
                    exact
                    path="/en/account/quiz/:slug/result"
                    component={QuizResult}
                  />

                  <PrivateRoute
                    exact
                    path="/en/account/my-books"
                    component={MyBooks}
                  />
                  <PrivateRoute
                    exact
                    path="/en/account/logout"
                    component={Logout}
                  />
                  <RedirectRoute
                    exact
                    path="/en/register"
                    component={Register}
                  />
                  <RedirectRoute exact path="/en/login" component={Login} />
                </Suspense>
              </Layout>
              <Route component={NoMatch} />
            </Switch>
          </Fragment>
        </Provider>
      </Router>
    );

我想要的是让页面呈现相同的组件,直到获取下一个块为止,也许带有诸如youtube之类的顶部进度条

1 个答案:

答案 0 :(得分:0)

@NduJay我想您正在寻找的是解析器。参见https://www.npmjs.com/package/react-resolver

基本上,这个概念是在满足显示数据的数据要求之前,下一个组件不会渲染。