CreateBrowserHistory节流导致浏览器速度降低

时间:2018-06-20 14:03:16

标签: reactjs react-router react-router-v4 react-router-dom

我正在做一个React JS项目。 我还使用react-router-dom进行路由。

在访问网页时,我发现浏览器运行缓慢,在检查控制台区域后发现此消息。

Throttling history state changes to prevent the browser from hanging. (anonymous) @ createBrowserHistory.js?6e99:211

此错误指向createBrowserHistory.js?6e99:211文件。 早些时候,我认为这是浏览器问题,但这来自我的react项目。

当我用Google搜索它时,我没有解决方案。 任何人在与React JS一起工作时都遇到过此问题。

是否有可能我正在调用许多操作,并且对于每个操作,react组件都会重新呈现,这会导致问题。

AppRouter.js

import React from 'react';
import {BrowserRouter, Route, Switch} from 'react-router-dom';
import {TransitionGroup, CSSTransition} from 'react-transition-group';

import HomePage from './../components/HomePage';
import AboutUs from './../components/AboutUs';
import ContactUs from './../components/ContactUs';
import PageNotFound from './../components/PageNotFound';
import RestaurantList from '../components/RestaurantList';
import RestaurantMenu from '../components/RestaurantMenu';
import UserDetails from '../components/UserDetails';
import OrderConfirmation from '../components/OrderConfirmation';
import CustomerAccount from '../components/CustomerAccount';

export default () => {
    return (
        <BrowserRouter>
            <Route render={({location}) => (
                <TransitionGroup>
                    <CSSTransition key={location.key} timeout={300} classNames="fade">
                        <Switch location={location}>
                            <Route path="/" component={HomePage} exact={true}/>
                            <Route path="/about" component={AboutUs} />
                            <Route path="/contact" component={ContactUs} />
                            <Route path="/restaurants" component={RestaurantList} />
                            <Route path="/select-menu" component={RestaurantMenu} />
                            <Route path="/user-details" component={UserDetails} />
                            <Route path="/order-confirmation" component={OrderConfirmation} />
                            <Route path="/my-account" component={CustomerAccount} />
                            <Route component={PageNotFound} />
                        </Switch>
                    </CSSTransition>
                </TransitionGroup>
            )} />

        </BrowserRouter>
    );
}

0 个答案:

没有答案