我将如何使Vue路由器与GitHub页面一起使用?

发布于 2025-01-23 23:03:59 字数 562 浏览 0 评论 0原文

我刚刚使用github页面将我的VUE应用程序部署到了我的网站。

该网站成功托管在 https://astroorbis.com

这是问题;当您单击页面顶部的“链接”按钮时,它将您成功地将您纳入 https://astroorbis.com/链接,但是当您尝试访问URL本身时(输入 https://astroorbis.com/links )进入您的浏览器,它返回404。

还有其他具有相同错误的链接,例如/discord,/github等。

我在

解决方案是什么?

I just deployed my Vue app to my website using GitHub Pages.

The website is successfully hosted at https://astroorbis.com.

Here's the problem; When you click the "links" button at the top of the page, it successfully nagivates you to https://astroorbis.com/links, but when you try visiting the URL itself (typing in https://astroorbis.com/links) into your browser, it returns a 404.

There are other links that have the same error, such as /discord, /github, etc.

I tried the solution at Vue Router, GitHub Pages, and Custom Domain Not Working With Routed Links, but it failed as well.

What would be the solution for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡水深流 2025-01-30 23:03:59

此部分的HTML5模式

不过,这是一个问题:由于我们的应用程序是一个单页客户端应用程序,没有适当的服务器配置,因此,如果他们访问 https://example.com/user/id 直接在其浏览器中。现在这很丑陋。

不用担心:要解决这个问题,您需要做的就是向服务器添加一个简单的捕获途径。如果URL与任何静态资产不匹配,则应提供您应用程序所居住的相同索引。

因此,解决方案将是使用喜欢

const routes = [
  // will match everything and put it under `$route.params.pathMatch`
  { path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound },
]

在Netlify上,您还需要添加以下内容才能工作
/public/_redirects

/* /index.html 200

所以我不确定github页面,但是您应该在那里有类似的东西,某种方法可以捕捉所有路线并将其发送到index.html您的初始水疗页面加载。

否则,也许只是尝试使用_redirects配置进行Netlify。


也许 /a>在GitHub页面上可能会有所帮助。

您给定链接中的黑客似乎是唯一可行的解​​决方案,但对SEO仍然不利,所以,是的,取决于您是否想要(我想)。
在这种情况下,如果您想拥有一些静态生成的页面(有关SEO的最佳方法),则可以尝试NUXT.JS,网格或Vitesse。

As stated in this section of the HTML5 mode

Here comes a problem, though: Since our app is a single page client side app, without a proper server configuration, the users will get a 404 error if they access https://example.com/user/id directly in their browser. Now that's ugly.

Not to worry: To fix the issue, all you need to do is add a simple catch-all fallback route to your server. If the URL doesn't match any static assets, it should serve the same index.html page that your app lives in. Beautiful, again!

So, the solution would be to use something like that

const routes = [
  // will match everything and put it under `$route.params.pathMatch`
  { path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound },
]

On Netlify, you also need to add the following for it to work
/public/_redirects

/* /index.html 200

So I'm not sure about Github Pages but you should have something similar there, some way of catching all routes and sending them to the index.html of your initial SPA page load.

Otherwise maybe just give a try to Netlify with the _redirects configuration.


Maybe this article could help regarding Github pages.

The hack in your given link seems to be the only viable solution but it's still bad for SEO so yeah, depends if you want any (I guess so).
In that case, you could try Nuxt.js, Gridsome or Vitesse if you want to have some statically generated pages (best approach regarding SEO).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文