Dynamic Importing of an unknown component - NextJs

前端 未结 3 1704
心在旅途
心在旅途 2021-01-20 01:05

I want to load a component dynamically based on the route. I\'m trying to make a single page which can load any individual component for testing purposes.

However whe

3条回答
  •  萌比男神i
    2021-01-20 01:22

    I put dynamic outside of the component, and it work fine.

    const getDynamicComponent = (c) => dynamic(() => import(`../components/${c}`), {
      ssr: false,
      loading: () => 

    Loading...

    , }); const Test = () => { const router = useRouter(); const { component } = router.query; const DynamicComponent = getDynamicComponent(component); return }

提交回复
热议问题