connected-react-router + redux-thunk asynchronous jump routing, will constantly modify the address and cause...












0















<Redirect exact from="/" to="/home" /> + setTimeout(() => dispatch(push('/')), 1e3) 


will cause:




Uncaught RangeError: Maximum call stack size exceeded




environment:



"connected-react-router": "^6.0.0",
"history": "^4.7.2",
"prop-types": "^15.6.2",
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react-redux": "^6.0.0",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"


component:



import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { increment, decrement } from '../actions/counter'
import { push } from 'connected-react-router';

const Counter = (props) => (
<div>
Counter: {props.count}
<button onClick={props.increment}>+</button>
<button onClick={props.decrement}>-</button>
<button onClick={props.back}>back</button>
</div>
)

Counter.propTypes = {
count: PropTypes.number,
increment: PropTypes.func.isRequired,
decrement: PropTypes.func.isRequired,
}

const mapStateToProps = state => ({
count: state.count,
})

const mapDispatchToProps = dispatch => ({
increment: () => dispatch(increment()),
decrement: () => dispatch(decrement()),
back: () => {
setTimeout(() => dispatch(push('/')), 1e3)
}
})

export default connect(mapStateToProps, mapDispatchToProps)(Counter)


router.js



import React from 'react'
import { Route, Switch, Redirect } from 'react-router'
import Home from '../components/Home'
import Hello from '../components/Hello'
import Counter from '../components/Counter'
import NoMatch from '../components/NoMatch'
import NavBar from '../components/NavBar'

const routes = (
<div>
<NavBar />
<Switch>
<Redirect exact from="/" to="/home" />
<Route path="/home" component={Home} />
<Route path="/hello" component={Hello} />
<Route path="/counter" component={Counter} />
<Route component={NoMatch} />
</Switch>
</div>
)

export default routes









share|improve this question





























    0















    <Redirect exact from="/" to="/home" /> + setTimeout(() => dispatch(push('/')), 1e3) 


    will cause:




    Uncaught RangeError: Maximum call stack size exceeded




    environment:



    "connected-react-router": "^6.0.0",
    "history": "^4.7.2",
    "prop-types": "^15.6.2",
    "react": "^16.6.0",
    "react-dom": "^16.6.0",
    "react-redux": "^6.0.0",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0"


    component:



    import React from 'react'
    import PropTypes from 'prop-types'
    import { connect } from 'react-redux'
    import { increment, decrement } from '../actions/counter'
    import { push } from 'connected-react-router';

    const Counter = (props) => (
    <div>
    Counter: {props.count}
    <button onClick={props.increment}>+</button>
    <button onClick={props.decrement}>-</button>
    <button onClick={props.back}>back</button>
    </div>
    )

    Counter.propTypes = {
    count: PropTypes.number,
    increment: PropTypes.func.isRequired,
    decrement: PropTypes.func.isRequired,
    }

    const mapStateToProps = state => ({
    count: state.count,
    })

    const mapDispatchToProps = dispatch => ({
    increment: () => dispatch(increment()),
    decrement: () => dispatch(decrement()),
    back: () => {
    setTimeout(() => dispatch(push('/')), 1e3)
    }
    })

    export default connect(mapStateToProps, mapDispatchToProps)(Counter)


    router.js



    import React from 'react'
    import { Route, Switch, Redirect } from 'react-router'
    import Home from '../components/Home'
    import Hello from '../components/Hello'
    import Counter from '../components/Counter'
    import NoMatch from '../components/NoMatch'
    import NavBar from '../components/NavBar'

    const routes = (
    <div>
    <NavBar />
    <Switch>
    <Redirect exact from="/" to="/home" />
    <Route path="/home" component={Home} />
    <Route path="/hello" component={Hello} />
    <Route path="/counter" component={Counter} />
    <Route component={NoMatch} />
    </Switch>
    </div>
    )

    export default routes









    share|improve this question



























      0












      0








      0








      <Redirect exact from="/" to="/home" /> + setTimeout(() => dispatch(push('/')), 1e3) 


      will cause:




      Uncaught RangeError: Maximum call stack size exceeded




      environment:



      "connected-react-router": "^6.0.0",
      "history": "^4.7.2",
      "prop-types": "^15.6.2",
      "react": "^16.6.0",
      "react-dom": "^16.6.0",
      "react-redux": "^6.0.0",
      "react-router": "^4.3.1",
      "react-router-dom": "^4.3.1",
      "redux": "^4.0.1",
      "redux-thunk": "^2.3.0"


      component:



      import React from 'react'
      import PropTypes from 'prop-types'
      import { connect } from 'react-redux'
      import { increment, decrement } from '../actions/counter'
      import { push } from 'connected-react-router';

      const Counter = (props) => (
      <div>
      Counter: {props.count}
      <button onClick={props.increment}>+</button>
      <button onClick={props.decrement}>-</button>
      <button onClick={props.back}>back</button>
      </div>
      )

      Counter.propTypes = {
      count: PropTypes.number,
      increment: PropTypes.func.isRequired,
      decrement: PropTypes.func.isRequired,
      }

      const mapStateToProps = state => ({
      count: state.count,
      })

      const mapDispatchToProps = dispatch => ({
      increment: () => dispatch(increment()),
      decrement: () => dispatch(decrement()),
      back: () => {
      setTimeout(() => dispatch(push('/')), 1e3)
      }
      })

      export default connect(mapStateToProps, mapDispatchToProps)(Counter)


      router.js



      import React from 'react'
      import { Route, Switch, Redirect } from 'react-router'
      import Home from '../components/Home'
      import Hello from '../components/Hello'
      import Counter from '../components/Counter'
      import NoMatch from '../components/NoMatch'
      import NavBar from '../components/NavBar'

      const routes = (
      <div>
      <NavBar />
      <Switch>
      <Redirect exact from="/" to="/home" />
      <Route path="/home" component={Home} />
      <Route path="/hello" component={Hello} />
      <Route path="/counter" component={Counter} />
      <Route component={NoMatch} />
      </Switch>
      </div>
      )

      export default routes









      share|improve this question
















      <Redirect exact from="/" to="/home" /> + setTimeout(() => dispatch(push('/')), 1e3) 


      will cause:




      Uncaught RangeError: Maximum call stack size exceeded




      environment:



      "connected-react-router": "^6.0.0",
      "history": "^4.7.2",
      "prop-types": "^15.6.2",
      "react": "^16.6.0",
      "react-dom": "^16.6.0",
      "react-redux": "^6.0.0",
      "react-router": "^4.3.1",
      "react-router-dom": "^4.3.1",
      "redux": "^4.0.1",
      "redux-thunk": "^2.3.0"


      component:



      import React from 'react'
      import PropTypes from 'prop-types'
      import { connect } from 'react-redux'
      import { increment, decrement } from '../actions/counter'
      import { push } from 'connected-react-router';

      const Counter = (props) => (
      <div>
      Counter: {props.count}
      <button onClick={props.increment}>+</button>
      <button onClick={props.decrement}>-</button>
      <button onClick={props.back}>back</button>
      </div>
      )

      Counter.propTypes = {
      count: PropTypes.number,
      increment: PropTypes.func.isRequired,
      decrement: PropTypes.func.isRequired,
      }

      const mapStateToProps = state => ({
      count: state.count,
      })

      const mapDispatchToProps = dispatch => ({
      increment: () => dispatch(increment()),
      decrement: () => dispatch(decrement()),
      back: () => {
      setTimeout(() => dispatch(push('/')), 1e3)
      }
      })

      export default connect(mapStateToProps, mapDispatchToProps)(Counter)


      router.js



      import React from 'react'
      import { Route, Switch, Redirect } from 'react-router'
      import Home from '../components/Home'
      import Hello from '../components/Hello'
      import Counter from '../components/Counter'
      import NoMatch from '../components/NoMatch'
      import NavBar from '../components/NavBar'

      const routes = (
      <div>
      <NavBar />
      <Switch>
      <Redirect exact from="/" to="/home" />
      <Route path="/home" component={Home} />
      <Route path="/hello" component={Hello} />
      <Route path="/counter" component={Counter} />
      <Route component={NoMatch} />
      </Switch>
      </div>
      )

      export default routes






      reactjs react-router redux-thunk connected-react-router






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 12:07









      user5377037

      7,482122861




      7,482122861










      asked Jan 2 at 7:58









      Zachary ZhouZachary Zhou

      12




      12
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003002%2fconnected-react-router-redux-thunk-asynchronous-jump-routing-will-constantly%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003002%2fconnected-react-router-redux-thunk-asynchronous-jump-routing-will-constantly%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          Npm cannot find a required file even through it is in the searched directory