Mixed development, embed the vue single page I wrote through webview, but found that $router.go (- 1) is invalid.

that"s the question!
mixed development, embed the vue single page that I wrote through webview, but found that $router.go (- 1) is invalid and can"t be used, but I have no problem in Android and browser


vue, you use vue route jump, $router.push ({name:'index',params: {}});


want to know how the landlord solved it? Ask for help


have you solved the problem

I found the problem. Because window.history.length is 1, you can't fall back when it is 1. You can ask Android and ios developers to write a method to call the native fallback

if (window.history.length == 1) {
    //    
        if (iphoneType === 'ios') {
    window.webkit.messageHandlers.nativeGoBack.postMessage({
                name: '-1'
            });
        } else if (iphoneType === 'Android') {
            window.jsCallOCFunction.nativeGoBack(-1);
        }
    } else {
        router.go(length)
    }

is probably through the route guard, caching the page's name to an array of localStorage when entering a page. Then read the array when you click back, and then jump through router.push ({name}) to achieve the fallback effect.


encounters the same problem, but this push method has a flaw. For example, when you use list state caching in keep-alive, the push method cannot be cached. After entering the details, you will not be able to reach the status of the previous browsing location when you go back.

Menu