Comments (9)
I'll take a look soon
from redux-react-router.
Fixed in 4.0.0-next.2
However, you should use <Navigate />
or wrap the dispatch(push('/'))
in a useEffect
.
from redux-react-router.
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.
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.
@lagunovsky
it works on react v18 ?
from redux-react-router.
@hellagutmann-soelen you can try version 4.0.0-next.0
from redux-react-router.
@lagunovsky In the example rep I updated to version 4.0.0-next.0
I uncommented the push dispatch
outside setTimeout
and commented the push dispatch inside setTimeout
in order to test this version:
In addition I also adjusted main.tsx
since it did not seem to support the timeline feature anymore (tsc is complaining)
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
Btw, seems like push is not able to dispatch the ON_LOCATION_CHANGED
action when you put it outside setTimeout.
push dispatch
outside setTimeout
push dispatch
inside setTimeout
from redux-react-router.
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.
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)
- examples reducers.tsx HOT 1
- Question about plans for package maintenance HOT 1
- Have an issue The prop `history` is marked as required in `Router`, but its value is `undefined`. HOT 5
- Cannot read properties of undefined (reading 'action') HOT 2
- Routes seem to be 'cached', trying to access the same route results in no navigation HOT 1
- Enable chosing different Routers. HOT 8
- Storing reducer with custom key HOT 2
- Using createBrowserRouter and other same functions HOT 3
- Missing class properties transform HOT 2
- You cannot render a <Router> inside another <Router> HOT 1
- Update to react-redux 9 HOT 1
- Can't call setState on a component that is not yet mounted.
- extend support for react v16 HOT 1
- Invalid error seen HOT 1
- React-redux v8 not supported HOT 3
- Browser's back button doesn't trigger @@router/ON_LOCATION_CHANGED HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-react-router.