React-router demand loading causes the js file packaged by webpack to contain css

this is router

import React from "react";
import {Route, Switch,Redirect} from "react-router-dom"
import {Layout} from "antd"
import "./content.less"
import asyncComponent from "./AsyncComponent"


const AsyncIndex = asyncComponent(() => import("../pages/index/index"))
const AsyncTrade = asyncComponent(() => import("../pages/order/Trade"))
const AsyncTransfer = asyncComponent(() => import("../pages/order/Transfer"))


const {Content} = Layout



export default class Contents extends React.Component {
  render() {
    return (
      <Content className="main-content">
        <Switch>
          <Route path="/merchant/console" exact component={AsyncIndex}/>
          <Route path="/trade/index" exact component={AsyncTrade}/>
          <Route path="/transfer/index" exact component={AsyncTransfer}/>
          <Redirect from="*" to="/merchant/console" />
        </Switch>
      </Content>
    );
  }
}

AsyncComponent

import React, { Component } from "react"

export default function asyncComponent(importComponent) {
  class AsyncComponent extends Component {
    constructor(props) {
      super(props)

      this.state = {
        component: null
      }
    }

    async componentDidMount() {
      const { default: component } = await importComponent()

      this.setState({
        component: component
      })
    }

    render() {
      const C = this.state.component

      return C ? <C {...this.props} /> : null
    }
  }

  return AsyncComponent
}

but after loading webpack on demand, the js file will be mixed with css

clipboard.png

could you tell me how to separate it

Mar.02,2021

it is included without on-demand loading.

The idea of

webpack is to use everything as modules, js, css, fonts, json, images,.

if not in the jsx file, import, can directly introduce

into html.
Menu