Răsfoiți Sursa

feat: openLink add replace params

zhangyuhan 3 ani în urmă
părinte
comite
d415eb817b
1 a modificat fișierele cu 17 adăugiri și 5 ștergeri
  1. 17 5
      packages/micro-frame/index.js

+ 17 - 5
packages/micro-frame/index.js

@@ -62,11 +62,12 @@ export function getPageRoute (link, needBase = false) {
  * @param options
  * @param options.type - 打开方式 iframe / qiankun
  * @param options.open - 是否新窗口打开
+ * @param options.replace - 是否使用 replace
  */
 export function openLink ({ link, options = {}}) {
   const router = getRouter()
   console.log('[parent] openLink', link)
-  const { type = 'iframe', open = false } = options
+  const { type = 'iframe', open = false, replace = false } = options
   let href
   switch (type) {
     case 'iframe': {
@@ -89,12 +90,23 @@ export function openLink ({ link, options = {}}) {
   if (open) {
     window.open(href)
   } else {
+
     if (type === 'outer') {
-      location.href = link
+      if (replace) {
+        location.replace(link)
+      } else {
+        location.href = link
+      }
     } else {
-      router.push({
-        path: href
-      })
+      if (replace) {
+        router.replace({
+          path: href
+        })
+      } else {
+        router.push({
+          path: href
+        })
+      }
     }
   }
 }