question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when trying to access a route with onEnter with an async function

See original GitHub issue

I’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:closed
  • Created 8 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
vedraancommented, Dec 2, 2015

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):

3reactions
mtdbcommented, Aug 12, 2015

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:

requireAuth: function(nextState, transition) {
    auth.loggedIn().then(function(loggedIn) {
        if (!loggedIn) transition.to('/login');
    });
}

auth.loggedIn() return a promise

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found