Error when trying to access a route with onEnter with an async function
See original GitHub issueI’m trying to put authentication on one of my routes with onEnter. I have the following code:
my route:
<Route path="/needauth" component={AuthComp} onEnter={validate}></Route>
my validate function:
function validate(nextState, transition, callback){
var isLoggedIn = yield asyncfunc(); // say that i called an async function here and stored the result in isLoggedIn
if(!isLoggedIn){
transition.to('/login');
}
callback();
});
}
When I try to access the route directly though, I get the following error:
Uncaught (in promise) TypeError: Cannot read property 'pathname' of null
at Object.shouldUpdateScrollPosition (webpack:///./~/react-router/lib/ScrollManagementMixin.js?:32:41)
at componentDidUpdate (webpack:///./~/react-router/lib/ScrollManagementMixin.js?:73:37)
at CallbackQueue.assign.notifyAll (webpack:///./~/react/lib/CallbackQueue.js?:68:22)
at ReactReconcileTransaction.ON_DOM_READY_QUEUEING.close (webpack:///./~/react/lib/ReactReconcileTransaction.js?:81:26)
at ReactReconcileTransaction.Mixin.closeAll (webpack:///./~/react/lib/Transaction.js?:207:25)
at ReactReconcileTransaction.Mixin.perform (webpack:///./~/react/lib/Transaction.js?:148:16)
at ReactUpdatesFlushTransaction.Mixin.perform (webpack:///./~/react/lib/Transaction.js?:134:20)
at ReactUpdatesFlushTransaction.assign.perform (webpack:///./~/react/lib/ReactUpdates.js?:95:38)
at Object.flushBatchedUpdates (webpack:///./~/react/lib/ReactUpdates.js?:175:19)
at Object.ReactPerf.measure.wrapper [as flushBatchedUpdates] (webpack:///./~/react/lib/ReactPerf.js?:70:21)
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Error when trying to access a route with onEnter with an async ...
I'm trying to put authentication on one of my routes with onEnter. I have the following code: my route: my validate function: function...
Read more >White page with async EnterHook in React Router while ...
I hydrate my server-side rendered DOM and everything works fine, if I don't use a callback inside my onEnter function. As soon as...
Read more >Async and Await | The Odin Project
The async keyword is what lets the JavaScript engine know that you are declaring an asynchronous function. This is required to use await...
Read more >NgZone - Angular
When a sync or async function is executed; When there is no microTask scheduled. NgZone run() and runOutsideOfAngular() link. Zone handles most asynchronous ......
Read more >React Router v6 Preview
If you want to match more of the URL because you have child routes (see the <Routes> defined in the Users component above),...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I realize this issue is closed but just to avoid confusion (I lost an hour or so after reading this issue and looking at the old docs linked above):
I don’t got errors when I use an async request, but the transition is not running, I am using es6 Promises, my code looks like:
auth.loggedIn()
return a promise