-
Notifications
You must be signed in to change notification settings - Fork 2k
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
12 changed files
with
10,710 additions
and
12,839 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@qiankunjs/ui-shared': patch | ||
'@qiankunjs/react': patch | ||
'@qiankunjs/vue': patch | ||
--- | ||
|
||
feat: refactor the code of microapp |
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,21 +1,51 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
/** | ||
* 渲染子应用 | ||
*/ | ||
function Render(props) { | ||
const { loading } = props; | ||
|
||
return ( | ||
<> | ||
{loading && <h4 className="subapp-loading">Loading...</h4>} | ||
<div id="subapp-viewport" /> | ||
</> | ||
); | ||
import React, { useEffect, useState } from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { MicroApp } from '@qiankunjs/react'; | ||
// 调试使用,注意 React 多实例问题 | ||
// import { MicroApp } from '../../../packages/ui-bindings/react/dist/esm/'; | ||
import '../index.less'; | ||
|
||
const root = ReactDOM.createRoot( | ||
document.getElementById('subapp-container'), | ||
); | ||
const sidemenu = document.querySelector('.mainapp-sidemenu'); | ||
|
||
const microApps = [ | ||
{ name: 'react15', entry: '//localhost:7102' }, | ||
{ name: 'react16', entry: '//localhost:7100' }, | ||
]; | ||
|
||
function App() { | ||
const [appName, setAppName] = useState(''); | ||
|
||
const handleMenuClick = (e) => { | ||
const app = microApps.find((app) => app.name === e.target.dataset.value); | ||
if (app && app.name !== appName) { | ||
setAppName(app.name); | ||
} else { | ||
console.log('not found any app'); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
sidemenu.addEventListener('click', handleMenuClick); | ||
|
||
return () => { | ||
sidemenu.removeEventListener('click', handleMenuClick); | ||
} | ||
}, []); | ||
|
||
if (appName) { | ||
const appEntry = microApps.find((app) => app.name === appName)?.entry; | ||
return <MicroApp name={appName} entry={appEntry} autoCaptureError />; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export default function render({ loading }) { | ||
const container = document.getElementById('subapp-container'); | ||
ReactDOM.render(<Render loading={loading} />, container); | ||
function reactRender() { | ||
// 将组件挂载到指定的节点上 | ||
root.render(<App />); | ||
} | ||
|
||
reactRender(); |
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 |
---|---|---|
|
@@ -27,5 +27,6 @@ | |
}, | ||
"browserslist": [ | ||
"last 2 Chrome versions" | ||
] | ||
} | ||
], | ||
"repository": "[email protected]:umijs/qiankun.git" | ||
} |
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
Oops, something went wrong.