mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-26 01:33:02 +00:00
refactor(core): type improvements for `PendingNavigation` (#5580)
* Fix type * Completely fix * Fix type
This commit is contained in:
parent
7f770ae621
commit
e0aa87fe7f
|
|
@ -23,7 +23,7 @@ function App(): JSX.Element {
|
|||
<BrowserContextProvider>
|
||||
<Root>
|
||||
<BaseUrlIssueBanner />
|
||||
<PendingNavigation routes={routes}>
|
||||
<PendingNavigation routes={routes} delay={1000}>
|
||||
{renderRoutes(routes)}
|
||||
</PendingNavigation>
|
||||
</Root>
|
||||
|
|
|
|||
|
|
@ -6,29 +6,30 @@
|
|||
*/
|
||||
|
||||
import React from 'react';
|
||||
import {Route, withRouter} from 'react-router-dom';
|
||||
import {Route, withRouter, RouteComponentProps} from 'react-router-dom';
|
||||
import {RouteConfig} from 'react-router-config';
|
||||
import nprogress from 'nprogress';
|
||||
|
||||
import clientLifecyclesDispatcher from './client-lifecycles-dispatcher';
|
||||
import preload from './preload';
|
||||
import normalizeLocation from './normalizeLocation';
|
||||
import type {Location} from '@docusaurus/history';
|
||||
|
||||
import './nprogress.css';
|
||||
|
||||
nprogress.configure({showSpinner: false});
|
||||
|
||||
interface Props {
|
||||
interface Props extends RouteComponentProps {
|
||||
routes: RouteConfig[];
|
||||
delay: number;
|
||||
location: any;
|
||||
location: Location;
|
||||
}
|
||||
interface State {
|
||||
nextRouteHasLoaded: boolean;
|
||||
}
|
||||
|
||||
class PendingNavigation extends React.Component<Props, State> {
|
||||
previousLocation: any;
|
||||
previousLocation: Location | null;
|
||||
progressBarTimeout: NodeJS.Timeout | null;
|
||||
|
||||
constructor(props: Props) {
|
||||
|
|
@ -46,7 +47,7 @@ class PendingNavigation extends React.Component<Props, State> {
|
|||
// is done loading.
|
||||
shouldComponentUpdate(nextProps: Props, nextState: State) {
|
||||
const routeDidChange = nextProps.location !== this.props.location;
|
||||
const {routes, delay = 1000} = this.props;
|
||||
const {routes, delay} = this.props;
|
||||
|
||||
// If `routeDidChange` is true, means the router is trying to navigate to a new
|
||||
// route. We will preload the new route.
|
||||
|
|
@ -128,4 +129,4 @@ class PendingNavigation extends React.Component<Props, State> {
|
|||
}
|
||||
}
|
||||
|
||||
export default withRouter(PendingNavigation as any) as any;
|
||||
export default withRouter(PendingNavigation);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
type Location = {pathname: string};
|
||||
import type {Location} from '@docusaurus/history';
|
||||
|
||||
// Memoize previously normalized pathnames.
|
||||
const pathnames: Record<string, string> = {};
|
||||
|
|
|
|||
Loading…
Reference in New Issue