React - Dynamically Import Components

前端 未结 8 1689
别那么骄傲
别那么骄傲 2020-12-05 07:14

I have a page which renders different components based on user input. At the moment, I have hard coded the imports for each component as shown below:

    imp         


        
8条回答
  •  执念已碎
    2020-12-05 08:16

    You can use Route and Switch from 'react-router-dom' to dynamically render components based on the path. Here is the sample

    render() {
    return (
      <>
        
    ()}/> ()}/> ()}/>
    ); }

提交回复
热议问题