如何使用 webview 为 VSCode 扩展实现 React App 导航

亚历克斯·菲拉托夫

我在VSCode Extension使用React. 我知道这VSCode允许HTML/JS/CSS使用Webview. 但是链接不起作用,因此react-router对于 Web 不起作用。

不起作用:


<Link to="/my/url">

我的问题是如何使用 React 导航实现到 vscode 扩展 webview 的导航?

任何帮助或建议表示赞赏。

101箭头z

如果您只想在react-router没有任何 URL 支持的情况下将您的组件链接在一起(即在您的这个扩展中),您可以使用createMemoryHistory. 请参阅不更改 URL 的响应路由器还要考虑MemoryRouterreact-routerV4。

例子:

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>
  );
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章