我在使用 React
开发 VSCode Extension
时遇到了这个问题。我知道 VSCode
允许使用 Webview
集成 HTML/JS/CSS
代码。但链接不起作用,因此 Web 版的 react-router
不起作用。
不起作用:
<Link to="/my/url">
我的问题是如何使用 React 导航实现到 vscode 扩展 webview 的导航?
如有任何帮助或建议,我们将不胜感激。
最佳答案
如果您想纯粹使用 react-router
将组件链接在一起,而不需要任何 URL 支持(即在您的扩展中),则可以使用 createMemoryHistory
。请参阅React Router Without Changing URL 。另请考虑MemoryRouter
对于 react-router
v4。
示例:
import { MemoryRouter } from 'react-router-dom';
const App = () => {
return (
<MemoryRouter>
{/* All your routes, i.e. stuff you usually put in <Router>.
Link elements now work because the "URL" is stored in memory. */}
</MemoryRouter>
);
}
关于javascript - 如何使用 webview 为 VSCode 扩展实现 React App 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59637276/