-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(1.0.0-beta.4): Optimize iframe support for disable memory router
- Loading branch information
1 parent
81ac2e9
commit 0e1bba2
Showing
14 changed files
with
158 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
node_modules | ||
.DS_Store | ||
dist | ||
vite2 | ||
dist-ssr | ||
*.local | ||
/vite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ lerna-debug.log* | |
|
||
node_modules | ||
dist | ||
vite4 | ||
dist-ssr | ||
*.local | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ import { | |
} from '../../interact' | ||
import { | ||
patchIframeRoute, | ||
actionsForDisableMemoryRoute, | ||
} from './route' | ||
import { | ||
router, | ||
|
@@ -160,19 +159,33 @@ export default class IframeSandbox { | |
}: SandBoxStartParams): void { | ||
if (this.active) return | ||
this.active = true | ||
if (useMemoryRouter) { | ||
this.initRouteState(defaultPage) | ||
// unique listener of popstate event for sub app | ||
this.removeHistoryListener = addHistoryListener( | ||
this.microAppWindow.__MICRO_APP_NAME__, | ||
) | ||
} else { | ||
// actions when memory-route disable | ||
actionsForDisableMemoryRoute( | ||
this.microAppWindow.__MICRO_APP_NAME__, | ||
this.microAppWindow, | ||
baseroute, | ||
) | ||
/** | ||
* Sync router info to iframe when exec sandbox.start with disable or enable memory-router | ||
* e.g.: | ||
* [email protected] get target path by remove the base section from rawLocation.pathname | ||
* code: window.location.pathname.slice(base.length) || '/'; (base is baseroute) | ||
* NOTE: | ||
* 1. iframe router and browser router are separated, we should update iframe router manually | ||
* 2. withSandbox location is browser location when disable memory-router, so no need to do anything | ||
*/ | ||
/** | ||
* 做一些记录: | ||
* 1. iframe关闭虚拟路由系统后,default-page无法使用,推荐用户直接使用浏览器地址控制首页渲染 | ||
* 补充:keep-router-state 也无法配置,因为keep-router-state一定为true。 | ||
* 2. 导航拦截、current.route 可以正常使用 | ||
* 3. 可以正常控制子应用跳转,方式还是自上而下(也可以是子应用内部跳转,这种方式更好一点,减小对基座的影响,不会导致vue的循环刷新) | ||
* 4. 关闭虚拟路由以后会对应 route-mode='custom' 模式,包括with沙箱也会这么做 | ||
* 5. 关闭虚拟路由是指尽可能模式没有虚拟路由的情况,子应用直接获取浏览器location和history,控制浏览器跳转 | ||
*/ | ||
this.initRouteState(defaultPage) | ||
|
||
// unique listener of popstate event for child app | ||
this.removeHistoryListener = addHistoryListener( | ||
this.microAppWindow.__MICRO_APP_NAME__, | ||
) | ||
|
||
if (!useMemoryRouter) { | ||
this.microAppWindow.__MICRO_APP_BASE_ROUTE__ = this.microAppWindow.__MICRO_APP_BASE_URL__ = baseroute | ||
} | ||
|
||
/** | ||
|
@@ -198,15 +211,16 @@ export default class IframeSandbox { | |
keepRouteState, | ||
destroy, | ||
clearData, | ||
useMemoryRouter, | ||
}: SandBoxStopParams): void { | ||
if (!this.active) return | ||
this.recordAndReleaseEffect({ clearData }, !umdMode || destroy) | ||
|
||
if (this.removeHistoryListener) { | ||
this.clearRouteState(keepRouteState) | ||
// release listener of popstate | ||
this.removeHistoryListener() | ||
} | ||
// if keep-route-state is true or disable memory-router, preserve microLocation state | ||
this.clearRouteState(keepRouteState || !useMemoryRouter) | ||
|
||
// release listener of popstate for child app | ||
this.removeHistoryListener?.() | ||
|
||
if (!umdMode || destroy) { | ||
this.deleteIframeElement() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ import { | |
import { | ||
assign, | ||
} from '../../libs/utils' | ||
import globalEnv from '../../libs/global_env' | ||
|
||
export function patchIframeRoute ( | ||
appName: string, | ||
|
@@ -52,34 +51,3 @@ export function patchIframeRoute ( | |
childHost, | ||
) | ||
} | ||
|
||
/** | ||
* actions when memory-route disable | ||
* @param appName app name | ||
* @param microAppWindow iframeWindow | ||
* @param baseroute base route for child app | ||
*/ | ||
export function actionsForDisableMemoryRoute ( | ||
appName: string, | ||
microAppWindow: microAppWindowType, | ||
baseroute: string, | ||
): void { | ||
microAppWindow.__MICRO_APP_BASE_ROUTE__ = microAppWindow.__MICRO_APP_BASE_URL__ = baseroute | ||
|
||
/** | ||
* Sync browser router info to iframe when disable memory-router | ||
* e.g.: | ||
* [email protected] get target path by remove the base section from location.pathname | ||
* code: window.location.pathname.slice(base.length) || '/'; (base is baseroute) | ||
* NOTE: | ||
* 1. iframe router and browser router are separated, we should update iframe router manually | ||
* 2. withSandbox location is browser location when disable memory-router, so no need to do anything | ||
*/ | ||
const rawLocation = globalEnv.rawWindow.location | ||
updateMicroLocation( | ||
appName, | ||
rawLocation.href, | ||
rawLocation, | ||
'prevent' | ||
) | ||
} |
Oops, something went wrong.