Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

history模式下,路由重定向的组件不显示

问题描述

学习vue路由时发现在history模式下打包后的项目打开时没有显示重定向的页面。(文件的导入路径都是正确的)

相关代码

//main.js
import Vue from 'vue'
import router from "./router/router.js"
import App from './App.vue'

Vue.config.productionTip = false
console.log(router);
new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
//app.vue
<template>
  <div id="app">
    <p>app</p>
    <router-view></router-view>
  </div>
</template>
//router.js
import vue from "vue";
import router from "vue-router";
vue.use(router);
import home from "../components/home"
...
const routes=[
  {path:"/",redirect: "/home"},
  {path:"/home",component:home},
  ...
]
const  Router=new router({
  routes,
  mode:"history"
})
export default Router;
//home.vue
<template>
    <div class="home">
      <p>首页</p>
      <p>
        <router-link to="/test">test</router-link>
        <router-link to="/about">about</router-link>
      </p>
    </div>
</template>

期望的页面

R~XA%8_7FB][XD)JJ4~%%`R.png

实际上的页面

0K69QY2H3W@80TF3(K5N@KB.png

是因为没有进行服务端配置还是其他原因?
求大佬指教


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

history 模式需要后台配置 nginx ,配置了吗? 参考链接https://router.vuejs.org/zh/g...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...