Coder Social home page Coder Social logo

Comments (9)

lagunovsky avatar lagunovsky commented on July 1, 2024 1

I'll take a look soon

from redux-react-router.

lagunovsky avatar lagunovsky commented on July 1, 2024 1

Fixed in 4.0.0-next.2

However, you should use <Navigate /> or wrap the dispatch(push('/')) in a useEffect.

from redux-react-router.

hellagutmann-soelen avatar hellagutmann-soelen commented on July 1, 2024

Odd, with a timeout everything seems to be working

const ProtectedRoute:FunctionComponent<Props> = ( props ) => {

  const authentication = useSelector( (state:RootState) => state.app.authentication );
  const state = useSelector( (state:RootState) => state );

  const dispatch = useDispatch<AppDispatch>()

  setTimeout( () => {

    if ( authentication === 'failed' ) {
    dispatch( push( '/' ) );
    }
  }, 1 );

  if( authentication === 'succeeded' ) return props.children;

  return <LinearProgress />;
}

from redux-react-router.

hellagutmann-soelen avatar hellagutmann-soelen commented on July 1, 2024

I created a small example here:

https://github.com/hellagutmann-soelen/react-router-v6-redux

After cloning, installing and starting you will see the issue by visiting http://localhost:4002/settings. You would think the dispatch( push( '/' ) ); in src/navigation/ProtectedNavigation/ProtectedNavigation.tsx would navigate settings back to signin correctly but this is simply not happening

from redux-react-router.

D3Pheonix avatar D3Pheonix commented on July 1, 2024

@lagunovsky
it works on react v18 ?

from redux-react-router.

lagunovsky avatar lagunovsky commented on July 1, 2024

@hellagutmann-soelen you can try version 4.0.0-next.0

from redux-react-router.

hellagutmann-soelen avatar hellagutmann-soelen commented on July 1, 2024

@lagunovsky In the example rep I updated to version 4.0.0-next.0

package.json

I uncommented the push dispatch outside setTimeout and commented the push dispatch inside setTimeout in order to test this version:

ProtectedNavigation.tsx

In addition I also adjusted main.tsx since it did not seem to support the timeline feature anymore (tsc is complaining)

main.tsx

Unfortunatly version 4.0.0-next.0 did not seems to fix the issue. Visiting localhost:4002/settings is not redirecting to / unless you put the push dispatch back into the setTimeout

image

Btw, seems like push is not able to dispatch the ON_LOCATION_CHANGED action when you put it outside setTimeout.

push dispatch outside setTimeout

image

push dispatch inside setTimeout

image

from redux-react-router.

hellagutmann-soelen avatar hellagutmann-soelen commented on July 1, 2024

Perhaps it has nothing to do with your package/software, in the weekend I tried to write a simple react redux routing for myself based on this example with similar issues. Perhaps it simply has something todo with the history package.

from redux-react-router.

hellagutmann-soelen avatar hellagutmann-soelen commented on July 1, 2024

Tested the example branch and different projects, seems to be working 👍

Thanks for the effort and please share your thoughts on my pr!

from redux-react-router.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.