Preface: you may encounter a such a problem, in the monitoring page, whether there is (such as refresh, close and other operations), just encountered such a project on the problem!!

Problem: I encountered a situation where when I refresh the page by pressing f5 on the browser (PC), if the tarbbar at the bottom is custom, I will return to the default 1. The solution is as follows:

[vue – the router beforeRouteEnter documentation] (navigation guard | vue router (vuejs.org))

BeforeRouteEnter (to, from, next) {next(vm = >{vm.tabbarList.filter((item, index) = >{ if (item.path === to.fullPath) { vm.currentItem = index vm.currentPath = to.fullPath } }) }) },Copy the code

Note: In beforeRouteEnter, this method cannot be used directly. If it is used, an error will be reported. Please pass a parameter to the next() method to handle variables, methods, etc in the vue instance.

Close: Write this down for yourself and your friend (you can skip it)