我在VSCode Extension
使用React
. 我知道这VSCode
允许HTML/JS/CSS
使用Webview
. 但是链接不起作用,因此react-router
对于 Web 不起作用。
不起作用:
<Link to="/my/url">
我的问题是如何使用 React 导航实现到 vscode 扩展 webview 的导航?
任何帮助或建议表示赞赏。
如果您只想在react-router
没有任何 URL 支持的情况下将您的组件链接在一起(即在您的这个扩展中),您可以使用createMemoryHistory
. 请参阅不更改 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>
);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句