简体   繁体   中英

How to reload current page in previous page after location.back (not SPA)

Cannot call a function in previous page's lifecycle which the page being killed.

I try to reload page A after page B being killed:

    // in Page B
    function backAndReload() {
        history.back()
        location.reload()
    }

The page A not being reloaded, because after history.back() the page B was killed and the code location.reload() will never be executed.

So I set a timeout:

    // in Page B
    function backAndReload() {
        setTimeout(() => {
            location.reload()
        }, 1000)
        history.back()
    }

But it didn't work as well.

So how to perform a task in a being killed page?

如果是非SPA页面,则无法执行此操作,因为当页面被杀死时, js线程也会被终止,因此所有未完成的任务也会被清除。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM