* 检查 url 变化是否需要跳转
(oldValues)
| 97 | * 检查 url 变化是否需要跳转 |
| 98 | */ |
| 99 | $_checkUrl(oldValues) { |
| 100 | if (!this.$_allowCheck) return false |
| 101 | |
| 102 | const window = cache.getWindow(this.$_pageId) |
| 103 | |
| 104 | if (this.$_protocol !== oldValues.protocol || this.$_hostname !== oldValues.hostname || this.$_port !== oldValues.port) { |
| 105 | // 只能跳转相同 protocol、hostname 和 port 的 url |
| 106 | const jumpUrl = this.href |
| 107 | |
| 108 | // 和 web 端不同,这里恢复成原状 |
| 109 | this.$_protocol = oldValues.protocol |
| 110 | this.$_hostname = oldValues.hostname |
| 111 | this.$_port = oldValues.port |
| 112 | this.$_pathname = oldValues.pathname |
| 113 | this.$_search = oldValues.search |
| 114 | this.$_hash = oldValues.hash |
| 115 | |
| 116 | window.$$trigger('pageaccessdenied', { |
| 117 | event: { |
| 118 | url: jumpUrl, |
| 119 | type: 'jump', |
| 120 | }, |
| 121 | }) |
| 122 | |
| 123 | return false |
| 124 | } |
| 125 | |
| 126 | if (this.$_pathname !== oldValues.pathname || this.$_search !== oldValues.search) { |
| 127 | const matchRoute = window.$$miniprogram.getMatchRoute(this.$_pathname) |
| 128 | |
| 129 | if (matchRoute) { |
| 130 | let param = ['type=jump', `targeturl=${encodeURIComponent(this.href)}`] |
| 131 | if (this.$_search) param.push(`search=${encodeURIComponent(this.$_search)}`) |
| 132 | if (this.$_hash) param.push(`hash=${encodeURIComponent(this.$_hash)}`) |
| 133 | |
| 134 | param = '?' + param.join('&') |
| 135 | |
| 136 | const callMethod = window.$$miniprogram.isTabBarPage(matchRoute) ? 'switchTab' : 'redirectTo' |
| 137 | wx[callMethod]({ |
| 138 | url: `${matchRoute}${param}`, |
| 139 | }) |
| 140 | |
| 141 | if (callMethod === 'switchTab') { |
| 142 | // switchTab 不会销毁页面实例,所以也需要恢复成原状 |
| 143 | this.$_protocol = oldValues.protocol |
| 144 | this.$_hostname = oldValues.hostname |
| 145 | this.$_port = oldValues.port |
| 146 | this.$_pathname = oldValues.pathname |
| 147 | this.$_search = oldValues.search |
| 148 | this.$_hash = oldValues.hash |
| 149 | } |
| 150 | |
| 151 | return true |
| 152 | } else { |
| 153 | const jumpUrl = this.href |
| 154 | |
| 155 | // 和 web 端不同,这里恢复成原状 |
| 156 | this.$_protocol = oldValues.protocol |