Vue路由器单页应用,应该重新加载页面吗?

时间:2017-12-11 09:45:08

标签: nginx vue.js vuejs2 vue-component vue-router

我有一个问题,我有vue路由器设置工作,但我有一个问题是如何单页应用程序。当我点击链接时,页面正在重新加载,因此它不是真正的单页应用程序吗?

这是我的nginx配置:

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/webuilder.co.uk/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name webuilder.co.uk;
    root /home/forge/webuilder.co.uk/current;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/webuilder.co.uk/279163/server.crt;
    ssl_certificate_key /etc/nginx/ssl/webuilder.co.uk/279163/server.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-$
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/webuilder.co.uk/server/*;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;

路线:

import Create from '../vue/components/homepage/create.vue';
import How from '../vue/components/homepage/how.vue';
import About from '../vue/components/homepage/about.vue';
import Youtube from '../vue/components/homepage/youtube.vue';
import Login from '../vue/components/auth/login.vue';
import Register from '../vue/components/auth/register.vue';

export default [
    { path: '/', component: Create },
    { path: '/how', component: How },
    { path: '/about', component: About},
    { name: 'youtube', path: '/youtube', component: Youtube},
    { path: '/login', component: Login},
    { path: '/register', component: Register},
];

Vue.use(VueRouter);
Vue.component('homenav', Navigation);
Vue.component('mainav', Navigation2);

const router = new VueRouter({
  mode: 'history',
  routes: Router
});

new Vue({
  el: '#nav',
  data: {
    nav: 'homeNav'
  },
  methods: {
    switchNav: function (nav) {
      this.nav = nav;
    }
  }
});

new Vue({
  el: '#app',
  router,
  updated: function () {
    Pace.restart()
  },
});

可以在以下网址看到:

https://webuilder.co.uk

有人可以解释并澄清这是否是SPA的预期行为?我认为它不会重新加载,但如果我关闭历史模式并添加' ...' ...

,则会更改组件本身。

1 个答案:

答案 0 :(得分:4)

当您想要路由到特定的路由器页面时,需要使用<router-link>而不是<a>

  

在HTML5历史记录模式下,router-link将拦截click事件,以便浏览器不会尝试重新加载页面。