简体   繁体   English

带有参数的 vue-router 无法在 netlify 上运行部署

[英]vue-router with parameter can't run deploy on netlify

Home.vue主页.vue

<template>
  <h3>Home</h3>
</template>

Test1.vue测试1.vue

<template>
  <h3>TEst page {{symbol}}</h3>
</template>

<script>
export default {
  data() {
      return {
        symbol: this.$route.params.id
      }
    },
}
</script>
export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/test/:id',
      component: Test1
    },
    {
      path: '/home',
      component: Home
    },
  ]
})

I can't call through the website [netlifylink/test/1].我无法通过网站 [netlifylink/test/1] 调用。 It's "Page Not Found Looks like you've followed a broken link or entered a URL that doesn't exist on this site".它是“页面未找到,您似乎访问了损坏的链接或输入了该站点上不存在的 URL”。

But can still access localhost:8080/test/1但是仍然可以访问 localhost:8080/test/1

i call localhost:8080/home and [netlifylink/home] is work.我打电话给 localhost:8080/home 并且 [netlifylink/home] 工作正常。 why?为什么?

help me please.Sorry for grammar.请帮帮我。对不起语法。

It's also in the Vue documentation deployment section它也在Vue文档部署部分

https://cli.vuejs.org/guide/deployment.html#netlify https://cli.vuejs.org/guide/deployment.html#netlify

In order to receive direct hits using history mode on Vue Router, you need to create a file called _redirects under /public with the following content:为了在 Vue Router 上使用history mode接收直接命中,您需要在/public下创建一个名为_redirects的文件,其内容如下:

# Netlify settings for single-page application
/*    /index.html   200

There are special deploy instructions for SPAs on Netlify. Netlify 上有针对 SPA 的特殊部署说明。 On this page: https://www.netlify.com/docs/redirects/ if you go to the History Pushstate and Single Page Apps section you will see this:在此页面上: https : //www.netlify.com/docs/redirects/如果您转到History Pushstate 和 Single Page Apps部分,您将看到:

If you're developing a single page app and want history pushstate to work so you get clean URLs, you'll want to enable the following rewrite rule:如果您正在开发单页应用程序并希望历史推送状态起作用以便您获得干净的 URL,您将需要启用以下重写规则:

/* /index.html 200 /* /index.html 200

This will effectively serve the index.html instead of giving a 404 no matter what URL the browser requests.无论浏览器请求什么 URL,这都将有效地为 index.html 提供服务,而不是给出 404。

You need to add this to the _redirects file under the root of your built site.您需要将其添加到已建站点根目录下的_redirects文件中。

create a file called netlify.toml in the root of your project and then paste this:在项目的根目录中创建一个名为netlify.toml的文件,然后粘贴:

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM