[英]Svelte-routing links removes base path in electron
I am working on an Electron.js application, utilizing Svelte as my frontend framework.我正在开发一个 Electron.js 应用程序,使用 Svelte 作为我的前端框架。 I am using the svelte-routing library for routing:我正在使用 svelte-routing 库进行路由:
<Router>
<Route path="">
//Home Page
<Link to="subpath">
</Route>
<Route path="subpath">
//Subpath
</Route>
</Router>
When a link is clicked it removes the base path, leaving only the subpath: I get: file:///subpath
instead of file:///path/to/project/public/index.html
in window.location
.单击链接时,它会删除基本路径,只留下子路径:我得到: file:///subpath
而不是file:///path/to/project/public/index.html
in window.location
。
The routing still works but when electron performs a hot reload all I get is a blank screen, and an error: Not allowed to load local resource: file:///subpath
路由仍然有效,但是当 electron 执行热重载时,我得到的只是一个空白屏幕,并且出现错误: Not allowed to load local resource: file:///subpath
How can I fix this?我怎样才能解决这个问题?
Hash routing would solve this. Hash 路由可以解决这个问题。 For example, instead of using a path /about
, you'd use #/about
.例如,不要使用路径/about
,而是使用#/about
。 In electron terms, that means file:///path/to/index.html#/about
在 electron 术语中,这意味着file:///path/to/index.html#/about
Unfortunately svelte-routing
does not support hash #
routing.不幸的是svelte-routing
不支持 hash #
路由。
One router that expressly supports it is @jamen/svelte-router
(there may be others).一个明确支持它的路由器是@jamen/svelte-router
(可能还有其他的)。
Here is an example usage of @james/svelte-router
:这是@james/svelte-router
的示例用法:
<!-- App.svelte -->
<script>
import {Router} from '@jamen/svelte-router'
import Home from './screens/Home.svelte'
import About from './screens/About.svelte'
const routes = {
"/": Home,
"/about": About
}
</script>
<Router {routes}/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.