1. 程式人生 > 程式設計 >解決vue+router路由跳轉不起作用的一項原因

解決vue+router路由跳轉不起作用的一項原因

如下所示:

Vue.use(Router)
export default new Router({
mode:'history',routes: [
   { path: '/',component: Login },{ path: '/login',{ path: '/register',component: Register},{path: '/*',component: NotFound},]
})

記得要寫上 mode:'history',原因如下

解決vue+router路由跳轉不起作用的一項原因

補充知識:vue-router配置後位址列輸入跳轉不成功問題

在起服務的js中增加 connect-history-api-fallback

const history = require('connect-history-api-fallback');
 
// 在靜態頁面之前,這一句:app.use('/static',express.static(__dirname + '/public'))之前設定history
const historyConfig = {
 index: '/index.html'
};
app.use(history(historyConfig));

以上這篇解決vue+router路由跳轉不起作用的一項原因就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。