nginx 去除井号操作 2

三步走

vue-Router 路由配置

const env = (process.env.NODE_ENV && process.env.NODE_ENV.trim() === 'production');
//页面导航
export const router = new VueRouter({
  //mode: "hash",
  mode: env ? 'history' : 'hash',
  routes: [
    {
        path: '/weChat',
        component: App,
        children: [
          {
            path: 'index',
            meta: { title: '小明' },
            component: r => require.ensure([], () => r(require('weChat/batch')), 'batch'),
          }, {
            path: 'log',
            meta: { title: '小红' },
            component: r => require.ensure([], () => r(require('weChat/log')), 'log'),
          }],
        },
  ]
});

Webpack 打包配置

const env = (process.env.NODE_ENV && process.env.NODE_ENV.trim() === 'production');

output: {
	publicPath: env ? '/weChat/' : '',
},

nginx 配置

#2018-10-16
location ~ ^/weChat/[\w/]+$ {
	try_files $uri $uri/ /weChat/index.html;
}

访问地址:

开发(dev)访问:http://localhost:9000/weChat/home/omdex

打包(build)访问:http://localhost:9000/#/weChat/home/index

你可能感兴趣的:(Vue)