0
reactjs動的インポートを使用しているときに奇妙な問題に直面しました。たとえば、名前がComponentA
で、そのパスがmyComponents/ComponentA
のようなコンポーネントがあるとします。今、私は動的に次のコードのようにそれをインポートするとき、それはうまく動作します:reactjs定数パス変数を使用した動的インポート
Promise.all(
[
import('myComponents/ComponentA'),
// other imports
]
).then(....);
しかし、私は次のように一定の変数での私のコンポーネントのパス定義した場合:
//before definition of my current component
const PATH = 'myComponents/ComponentA';
.
.
.
// some where in my component class
Promise.all(
[
import(PATH),
// other imports
]
).then(....);
を、それは私に与えるだろうこのようなエラー:
Error: Cannot find module 'myComponents/ComponentA'.
そして私はちょうど問題とそうでないいくつかの回を解決するだろう、私のPATH
変数に空の文字列を追加する場合、いくつかの回。
//before definition of my current component
const PATH = 'myComponents/ComponentA';
.
.
.
// some where in my component class
Promise.all(
[
import(''+PATH), // some times by adding empty string, problem would be solved
// other imports
]
).then(....);
何が起こっているかについてのご意見はありがたいです。
のHIとなっている願っています。あなたの反応のためのタンクが、動作しませんでした。 – pooyan
あなたはバックティックを試しましたか?私たちはこの 'import( '$ {PATH}')'のようなスペースで試してみることができます($ {PATH}はバックスティックでコメントできません) –
遅刻して申し訳ありませんが、これもうまくいきませんでした。 – pooyan