苗条的路线给我404 [英] Svelte route gives me 404

查看:90
本文介绍了苗条的路线给我404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Svelte中为我的应用程序创建了一个简单的路由器。
如果我从导航栏访问链接,则该链接正常。
如果重新加载页面,它会给我404。为什么?

I created a simple router for my app in Svelte. It is working if I'm accessing the link from the nav bar. If I reload the page, it give me 404.. why ?

<Router url="{url}">
 <nav>
   <Link to="/">Home</Link>
   <Link to="charts">About</Link>
 </nav>
 <div>
  <Route path="charts" component="{About}" />
  <Route path="/"><Home /></Route>
 </div>
</Router>

重新加载后:
找不到该本地主机页面网址: http:// localhost:5000 / charts

推荐答案

您必须确保您的服务器正在为每个路由路径提供 index.html ,而不仅仅是为 /

You must make sure your server is serving the index.html for every route path and not just for /.

如果将 sirv 与Svelte入门项目之一配合使用,您可以在脚本中添加-single 标志。

If you e.g. are using sirv with one of the Svelte starter projects you can add the --single flag to the script.

"scripts": {
  "start": "sirv public --single",
  "start:dev": "sirv public --dev --single"
},

这篇关于苗条的路线给我404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆