React Native: how to use require(path) with dynamic urls?

前端 未结 1 2080
醉酒成梦
醉酒成梦 2021-01-15 20:39

I want to use WebView to show some html content

here is an example:

return (
            

        
相关标签:
1条回答
  • 2021-01-15 20:42

    As you find out, you can't have dynamic url for require. That's because require get the source at the app start regardless it's place in the code. You shuld require all of the {languageId}text.html and pass the required variable to the source:

    var language = {
       en: require(`../srv/localization/contents/entext.html`)
       ...
    }
    

    and use it as below:

    source = require(language[en])
    
    0 讨论(0)
提交回复
热议问题