vue2.0 路由模式mode="history"的作用

特别提醒:开启mode="history"模式,需要服务端的支持,因为出现“刷新页面报错404”的问题;

大家都知道,路由地址都是以"#"形式展示,但是有些时候,我们又希望路由地址中不出现"#",那怎么办呢?

vue给我们提供了一个属性mode="history";代码如下

const router = new Router({
  mode: 'history',  // 去掉路由地址的#
  routes: [
    {
      path: '/',  // 默认进入路由[写在第一个]
      redirect: '/home'   //重定向
    },
    {
      path: '/login',
      name: 'login',
      component: LoginPage
    },
    {
      path: '**',   // 错误路由[写在最后一个]
      redirect: '/home'   //重定向
    }
  ]
});

Nginx配置改为:

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

猜你喜欢

转载自blog.csdn.net/yuan_jlj/article/details/89356443
今日推荐