Solution to refresh the ui router menu on second click in angulrjs

Add the following click event to the ui-sref element:

$scope.urlClick = function (event,navInfo) {
    var navUrl = window.location.href.split('#')||'';
    var hrefUrl = '1';
    if(event.target){
        hrefUrl = decodeURIComponent(event.target.getAttribute('href').replace('#',''))
    }
    if(navUrl && navUrl[1]){
        navUrl = decodeURIComponent(navUrl[1]);
    }
    console.log(hrefUrl);
    console.log(navUrl);
    if(hrefUrl.indexOf(navUrl) !== -1){
        $state.reload();
    }
}

 

1. Get the current url and find it. The url of dynamic parameters cannot be obtained directly using $state, so just use the native one and intercept it.

2. Because the dynamic URL with parameters is encoded, it needs to be decoded.

3. It is necessary to judge whether the path is included and cannot be judged to be equal, otherwise problems may occur.

Guess you like

Origin blog.csdn.net/lizhen_software/article/details/113311167