如何安装svelte_如何使用svelte和express js配置页面路由

如何安装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

The code above creates a simple Svelte app and uses svelte-routing as the routing solution. It then

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值