Javascript VUE JS相对路径问题

Javascript VUE JS相对路径问题,javascript,vue.js,vue-router,Javascript,Vue.js,Vue Router,我有一个vuejs简单项目,并将其部署到我的主机上 首先,我使用以下方法在生产模式上构建它: npm run build 然后我有一个url,它是www.sample.com/vue project/,我把我的vuejs项目的生产版本放在那里。当我访问链接时,一切正常。当我单击菜单添加博客时,它会更改此链接的urlwww.sample.com/vue project/add,并加载正确的组件。但是,当我按页面上的f5时,会出现404错误。但我不知道为什么。 当我访问此链接时https://e

我有一个vuejs简单项目,并将其部署到我的主机上

首先,我使用以下方法在生产模式上构建它:

 npm run build
然后我有一个url,它是
www.sample.com/vue project/
,我把我的vuejs项目的生产版本放在那里。当我访问链接时,一切正常。当我单击菜单添加博客时,它会更改此链接的url
www.sample.com/vue project/add
,并加载正确的组件。但是,当我按页面上的
f5
时,会出现
404错误
。但我不知道为什么。 当我访问此链接时
https://epm.sg/vue-project/#/add
它为我提供了正确的组件。但正如您在我的
路由选项上所看到的
我将其设置为
历史模式

这是我的密码

main.js

import VueResource from 'vue-resource'
import VueRouter from 'vue-router'
import Routes from './routes'

Vue.use(VueResource);
Vue.use(VueRouter);

Vue.url.options.root = 'https://sample-proj.firebaseio.com/';

const router = new VueRouter({
  base:'/vue-project/',
  routes:Routes,
  mode: 'history',
});
import showBlogs from './components/showBlogs.vue';
import addBlog from './components/addBlog.vue';
import singleBlog from './components/singleBlog.vue';

export default [
  {
    path: "/",
    component: showBlogs
  },
  {
    path: "/add",
    component: addBlog
  },
  {
    path: "/blog/:id",
    component: singleBlog
  }
];
routes.js

import VueResource from 'vue-resource'
import VueRouter from 'vue-router'
import Routes from './routes'

Vue.use(VueResource);
Vue.use(VueRouter);

Vue.url.options.root = 'https://sample-proj.firebaseio.com/';

const router = new VueRouter({
  base:'/vue-project/',
  routes:Routes,
  mode: 'history',
});
import showBlogs from './components/showBlogs.vue';
import addBlog from './components/addBlog.vue';
import singleBlog from './components/singleBlog.vue';

export default [
  {
    path: "/",
    component: showBlogs
  },
  {
    path: "/add",
    component: addBlog
  },
  {
    path: "/blog/:id",
    component: singleBlog
  }
];
导航栏.vue

<template>
  <nav>
      <ul>
        <li><router-link to="/" exact>Blog</router-link></li>
        <li><router-link to="/add" exact>Add New Blog</router-link></li>
      </ul>
  </nav>
</template>
<script>
export default {

}
</script>

  • 博客
  • 添加新博客
导出默认值{ }

提前感谢。

您将捆绑包(js/html/css文件)部署到的服务器是什么?@acdcjunior linux server sir。。实际上,我使用htaccess解决了这个问题。。现在没事了。谢谢你的回复,是的,这就是我要说的。你需要的一切都在这里~Hi@Phil谢谢你的回复。。。信息量很大。