Присвоение document.location.href, не ударяя историю

Вы можете использовать async await в handleLogin (). Таким образом, login () будет вызываться только после разрешения обещания signUp ().

async handleLogin(){
      const { name, email, password} = this.props; 
      await this.props.signUp( name, email, password)
      await this.props.login(email,  password)
      this.props.navigtion.navigate('Home')
    }

Другим способом было бы поместить login () в .then функции signUp (). Это будет работать так же, как асинхронное ожидание. Имя входа () будет вызвано после разрешения функции signUp (). Затем вы можете поместить navigate () в .then login (), если вы хотите перемещаться только после того, как пользователь вошел в систему.

handleLogin(){
      const { name, email, password} = this.props; 
      this.props.signUp( name, email, password)
      .then(this.props.login(email,  password)
      .then(this.props.navigtion.navigate('Home'))
      )
    }

Надеюсь, это поможет.

10
задан wolffiex 14 May 2009 в 20:32
поделиться

5 ответов

Я столкнулся с той же проблемой и нашел этот обходной путь, который сработал для меня

вместо

function onAjaxCallback(evt){
    location.href=newLocation;
}

. Я обернул вызов location.href вокруг setTimeout. Кажется, добился цели. Моя история сейчас в порядке. Надеюсь, что это поможет

function onAjaxCallback(evt){
    setTimeout(function(){
        location.href=newLocation;
    },0)
}
12
ответ дан 3 December 2019 в 20:06
поделиться

Alas, your question can't be answered, AJAX requests have nothing to do with browser history, and if you loaded some dynamic content with them, then the user clicked the browser back button, the previous page is loaded (this which was loaded with an ordinary GET or POST request), which corrupts the sequence you display content in.

Dmitri's answers means that you will maintain your own history for the dynamic content using the fragment part of the url (this after the # symbol), maybe you'll provide your own back and forward buttons, but still you're not protected from the effect of the browser back and forward buttons.

If only they had provided some kind of events to handle user clicks on these buttons with the ability to cancel.

-1
ответ дан 3 December 2019 в 20:06
поделиться

You could change the location without having the browser display a Back button like this:

window.location.replace(new_url);

However, the original address remains in the browser's history and may be accessed using something like CTRL+H

Reference:

4
ответ дан 3 December 2019 в 20:06
поделиться

Внимательно прочтите исходный вопрос. Вопрос не в контенте, загружаемом XHR, а в контенте , загружаемом скриптом , загружаемым XHR. У меня была та же проблема, и метод setTimeout, похоже, работает хорошо.

1
ответ дан 3 December 2019 в 20:06
поделиться

исследование: window.location.replace() и window.location.assign()

2
ответ дан 3 December 2019 в 20:06
поделиться
Другие вопросы по тегам:

Похожие вопросы: