The problem is that the URL you have ('/url/to/OtherComponent.js') is dynamic and could be fetched from an API. React.lazy can't directly handle dynamic URLs in this manner because it needs to resolve the module ahead of time.
Here's how you can handle this:
Ensure that the URL is known before passing to React.lazy: You can wrap the logic in a state or use a hook to fetch the URL using Fetch API, and only call React.lazy after the URL is known.
Use dynamic imports once the URL is available
React.lazy only accepts a dynamic import function, which works with static module paths.