Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

基于creat-react-app创建的主子应用,如果当前是子应用路由,修改主应用后报错:Iframe has not been created yet. #4173

Open
chenfangsheng opened this issue Mar 17, 2021 · 5 comments
Assignees
Labels

Comments

@chenfangsheng
Copy link

chenfangsheng commented Mar 17, 2021

前提:
1.主、子应用都是通过creat-react-app创建
场景重现:启动项目配置好主子应用后,可以正常打开,点击切换到子应用路由,修改主应用代码,热更新后,控制台报错:
Iframe has not been created yet.

子应用是这样注册的:
entry="//localhost:3000"

@ClarkXia
Copy link
Collaborator

尽量多提供点信息,比如配置方式

@chenfangsheng
Copy link
Author

chenfangsheng commented Mar 18, 2021

主应用:

import React, { useEffect } from "react";
import  { BrowserRouter } from 'react-router-dom'
import Loadable from "react-loadable";
import { AppRouter, AppRoute } from '@ice/stark';
import { appHistory } from '@ice/stark-app';
import { store } from '@ice/stark-data';
import { Menu } from "antd";
import "./App.scss";
// components
import { Loading } from "components";

function App() {

  useEffect(() => {
    const userInfo = { name: 'Tom', age: 18 };
    store.set('user', userInfo); // 设置登录后当前用户信息
  })

  const handleClick = ({key}: any) => appHistory.push(key);
  
  return (
    <div className="App">
      <header className="main-header">common header</header>

      <div>
        <Menu
          onClick={handleClick}
          style={{ width: 200 }}
          defaultSelectedKeys={['1']}
          defaultOpenKeys={['sub1']}
          mode="inline"
        >
          <Menu.Item key="/home">Main Page</Menu.Item>
          <Menu.Item key="/seller">Child Page</Menu.Item>
        </Menu>
      </div>
      
      <div>
        <AppRouter
          LoadingComponent={Loading}
        >
          <AppRoute
            path="/seller"
            title="商家平台"
            entry="//localhost:3000"
          />
          <AppRoute
            path="*"
            title="通用页面"
            render={() => {
              return (
                <BrowserRouter>
                  <LoadBasic />
                </BrowserRouter>
              )
            }}
          />
        </AppRouter>
      </div>
    </div>
  );
}

const LoadBasic = Loadable({
  loader: () => import("./layout/Basic"),
  loading: Loading,
});

export default App;

子应用:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { isInIcestark, setLibraryName } from '@ice/stark-app';

export function mount(props: any) {
  ReactDOM.render(<App {...props.customProps} />, props.container);
}

export function unmount(props: any) {
  ReactDOM.unmountComponentAtNode(props.container);
}

// 注意:`setLibraryName` 的入参需要与 webpack 工程配置的 output.library 保持一致
setLibraryName('microApp');

if (!isInIcestark()) {
  ReactDOM.render(
    <App />,
    document.getElementById('react-root')
  );
}

reportWebVitals();

@maoxiaoke
Copy link
Collaborator

@chenfangsheng 主子应用 demo 可以提供下吗?

@chenfangsheng
Copy link
Author

@chenfangsheng 主子应用 demo 可以提供下吗?

就是通过creat-react-app创建的

@maoxiaoke
Copy link
Collaborator

@chenfangsheng 开启 Fast Refresh 的项目可能会遇到这个问题(#10385),可以暂时关闭 Fast Refresh 功能。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants