Skip to content

Commit

Permalink
单页跳转透传 hash
Browse files Browse the repository at this point in the history
  • Loading branch information
zoumiaojiang authored and chenqiushi committed Jul 23, 2019
1 parent 6a799da commit 8414bba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/mip/examples/page/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h3>共享数据 checklist:</h3>
</p>

<a class="link" href="../builtin/mip-iframe.html" mip-link>Login</a>
<a class="link" href="./tree.html" mip-link data-title="Customized title">Go to Tree</a>
<a class="link" href="./tree.html?a=1#c=1&a=4" mip-link data-title="Customized title">Go to Tree</a>
<a class="link" href="./tree.html" mip-link cache-first>Go to Tree cache first</a>
<a class="link" id="prerender">Prerender</a>

Expand Down
18 changes: 16 additions & 2 deletions packages/mip/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author zhangzhiqiang(zhiqiangzhang37@163.com)
*/

/* global top screen location */
/* global top screen location, MIP */

import event from './util/dom/event'
import Gesture from './util/gesture/index'
Expand Down Expand Up @@ -266,9 +266,23 @@ let viewer = {
}
this.sendMessage(replace ? OUTER_MESSAGE_REPLACE_STATE : OUTER_MESSAGE_PUSH_STATE, pushMessage)

let routePath = (window.MIP.standalone && !window.MIP.util.isCacheUrl(location.href)) ? to : makeCacheUrl(to)
let routeSplits = routePath.split('#')
let hashStr = '#'
let curHashObj = MIP.hash._getHashObj(routeSplits[1] || '')
let targetHashObj = MIP.hash._getHashObj(location.hash)
let retObj = Object.assign({}, targetHashObj, curHashObj)

for (let key in retObj) {
hashStr += `${key}${retObj[key].sep}${retObj[key].value}&`
}

// hash 透传机制
routePath = routeSplits[0] + hashStr.substr(0, hashStr.length - 1)

// Create target route
let targetRoute = {
path: (window.MIP.standalone && !window.MIP.util.isCacheUrl(location.href)) ? to : makeCacheUrl(to)
path: routePath
}

if (isMipLink) {
Expand Down

0 comments on commit 8414bba

Please sign in to comment.