如何安装svelte
This tutorial is for anyone who creates single-page-apps and wants to know how to configure routing properly on the server side. It will use Svelte as the framework, but the techniques here will work for any app using client side routing.
本教程适用于创建单页应用程序并且想知道如何在服务器端正确配置路由的任何人。 它将使用Svelte作为框架,但是此处的技术将适用于所有使用客户端路由的应用程序。
The Problem
问题
Client-side routing solutions like svelte-routing
work great, but they will break if you try to refresh your page when using them, and this means that it’s impossible to use hot reloading. This is because all routing logic is performed on the client, and when you initially load a page, say localhost:5000/home
, the client code isn’t yet loaded. This means that your browser will attempt to find the file home.html
at localhost:5000
but it won’t be there, because it’s a single page app. It only has index.html
.
像svelte-routing
这样的客户端路由解决方案效果很好,但是如果您在使用它们时尝试刷新页面,它们将会中断,这意味着不可能使用热重装。 这是因为所有路由逻辑都是在客户端上执行的,并且当您最初加载页面(例如localhost:5000/home
,尚未加载客户端代码。 这意味着您的浏览器将尝试在localhost:5000
处找到文件home.html
,但由于它是一个单页应用程序,因此不会在其中。 它只有index.html
。
Here’s an example.
这是一个例子。
![Image for post](https://img-blog.csdnimg.cn/img_convert/aaabdacfda38d54d097cbe89117d475c.png)
The code above creates a simple Svelte app and uses svelte-routing
as the routing solution. It then