-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
5 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,5 +1,7 @@ | ||
import { isTurnChild } from "../utils"; | ||
// 每次路由切换打印事件 | ||
export const turnApp = ()=>{ | ||
console.log('路由切换了'); | ||
|
||
if (isTurnChild()) { | ||
console.log('路由切换了'); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,40 @@ | ||
import { getList } from "../const/subApps" | ||
|
||
// 给当前路由跳转打补丁 | ||
export const patchRouter = (globalEvent, eventName)=>{ | ||
return function(){ | ||
const e = new Event(eventName) | ||
globalEvent.apply(this, arguments) | ||
window.dispatchEvent(e) | ||
} | ||
} | ||
|
||
// 获取当前子应用 | ||
export const currentApp = ()=>{ | ||
const currentUrl = window.location.pathname | ||
return filterApp('activeRule', currentUrl) | ||
} | ||
|
||
|
||
// 过滤当前路由 | ||
const filterApp = (key, value)=>{// 当前key值===value值 | ||
|
||
const currentApp = getList().filter(item => item[key]===getCurrentPrefix()) // => array | ||
// console.log('currentApp', currentApp); | ||
|
||
return currentApp && currentApp.length ? currentApp[0]:{} | ||
} | ||
|
||
const getCurrentPrefix = (value=window.location.pathname)=>{ | ||
const currentPrefix = value.match(/(\/\w+)/g) | ||
return currentPrefix[0] | ||
} | ||
|
||
// 子应用是否做了切换 | ||
export const isTurnChild = ()=>{ | ||
|
||
if (window.__CURRENT_SUB_APP__===getCurrentPrefix()) { | ||
return false; | ||
} | ||
return true | ||
} |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { MicroStart } from '../../micro' | ||
|
||
const { registerMicroApps }= MicroStart | ||
const { registerMicroApps, start }= MicroStart | ||
// 注册子应用 | ||
export const registerApp=(list)=>{ | ||
// 注册到微前端框架 | ||
registerMicroApps(list) | ||
|
||
// 启动微前端框架 | ||
start() | ||
} |