|
@@ -104,9 +104,9 @@ export function openLinkOfAd ({ link, type = 'within', title = '', iosHref } = {
|
|
|
* @param config.query 请求参数
|
|
|
* @param config.type 打开形式 仅支持 replace、push
|
|
|
*/
|
|
|
-export function openLinkOfOther (link, config = {}) {
|
|
|
+export function openLinkOfOther (link, config = {}, router = routerVm) {
|
|
|
if (!link) return
|
|
|
- const { query = {}, type = 'push' } = config
|
|
|
+ const { query = {}, type = 'push', match = true } = config
|
|
|
let prefix = ''
|
|
|
if (NotURLPrefixRegExp.test(link)) {
|
|
|
if (inWeiXinBrowser) {
|
|
@@ -133,11 +133,83 @@ export function openLinkOfOther (link, config = {}) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+ const toLInkArr = toLink.split('?')
|
|
|
+ const toLinkQuery = toLInkArr[1]
|
|
|
+ const r = checkLinkRegistered(toLink, router)
|
|
|
+ // console.log(link, router, r)
|
|
|
+ if (match && r.path) {
|
|
|
+ const pArr = [r.path]
|
|
|
+ if (toLinkQuery) {
|
|
|
+ pArr.push(toLinkQuery)
|
|
|
+ }
|
|
|
+ const routeInfo = {
|
|
|
+ path: pArr.join('?'),
|
|
|
+ query: {
|
|
|
+ 'inside-jumps': 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (type !== 'push') {
|
|
|
+ router.replace(routeInfo)
|
|
|
+ } else {
|
|
|
+ router.push(routeInfo)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (type !== 'push') {
|
|
|
+ location.replace(toLink)
|
|
|
+ } else {
|
|
|
+ location.href = toLink
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 检查url是否在当前vue-router中注册过
|
|
|
+ * url: '/jyapp/free/set'
|
|
|
+ * url: 'https://app-jytest.jydev.jianyu360.com/jyapp/free/set'
|
|
|
+ * url: '/jy_mobile/tabbar/home'
|
|
|
+ * url: 'https://app-jytest.jydev.jianyu360.com/jy_mobile/tabbar/home'
|
|
|
+ *
|
|
|
+ * 检测到注册过url,则返回匹配到的路由对象
|
|
|
+ * 检测到注册过,则返回url
|
|
|
+ *
|
|
|
+ */
|
|
|
+export function checkLinkRegistered (url, router = routerVm) {
|
|
|
+ if (!url) return console.error('url为必传参数')
|
|
|
+ const routerBase = router.options.base || ''
|
|
|
+ let waitingMatchUrl = ''
|
|
|
+ const withDomain = url.includes('http://') || url.includes('https://')
|
|
|
+ // url中有域名。
|
|
|
+ if (withDomain) {
|
|
|
+ const u = new URL(url)
|
|
|
+ // 域名为剑鱼,并且pathname中有路由前缀(/jy_mobile/),进行匹配。否则直接进行跳转
|
|
|
+ if (u.host.includes('jianyu360')) {
|
|
|
+ waitingMatchUrl = u.pathname
|
|
|
+ } else {
|
|
|
+ return {
|
|
|
+ url
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ waitingMatchUrl = url
|
|
|
+ }
|
|
|
|
|
|
- if (type !== 'push') {
|
|
|
- location.replace(toLink)
|
|
|
+ // pathname中有路由前缀(/jy_mobile/),进行匹配并替换。否则直接进行跳转
|
|
|
+ const hasRouterBaseStart = waitingMatchUrl && waitingMatchUrl.match(new RegExp(`^${routerBase}/`))
|
|
|
+ if (hasRouterBaseStart) {
|
|
|
+ waitingMatchUrl = waitingMatchUrl.replace(new RegExp('^' + routerBase), '')
|
|
|
+ const r = router.matcher.match(waitingMatchUrl)
|
|
|
+ if (r.name === '404') {
|
|
|
+ return {
|
|
|
+ url
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return r
|
|
|
+ }
|
|
|
} else {
|
|
|
- location.href = toLink
|
|
|
+ // 直接返回url进行location.href跳转
|
|
|
+ return {
|
|
|
+ url
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|