history 模式,一个根目录下面挂多个站点

1、nginx配置

 location /one {
        alias /mnt/new_pro/web/one/dist;  //vue项目所在位置
		try_files $uri $uri/ /one/index.html;  
        index  index.html index.htm;
    }
    # 门店前端
   location /two{
        alias  /mnt/new_pro/web/two/dist;
	   try_files $uri $uri/ /two/index.html;
        index  index.html index.htm;
    }

如果跳转出现404是nginx配置未配置好,
Nginx 会将请求的 URI 完整地附加到 root 指定的路径上;alias 会替换掉 location 中匹配的部分,而不是简单地拼接;
例如,请求http://yourdomain/one/somefile时,root会尝试访问/mnt/new_pro/web/dist/one/somefile;alias 会尝试访问/mnt/new_pro/web/dist/somefile。
2、vue项目路由配置

const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'history', // 去掉url中的#
  base: '/one ',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

3、修改 vue.config.js 的 publicPath

publicPath: '/one /',

问题1:确定是否访问到相关项目
可将dist下的index.html文件的代码替换成以下代码,然后运行

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Simple Vue App</title>
</head>
<body>
  <div id="app">
    <h1>{{ message }}</h1>
    <button @click="changeMessage">点击我</button>
  </div>

  <!-- 引入 Vue.js -->
  <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
  <!-- 引入入口文件 -->
  <script src="main.js"></script>
</body>
</html>

页面为

即nginx配置正确
问题2 跳转正确,路由正确但是访问页面为空白
可能是 vue.config.js 的 publicPath未修改或者修改错误

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值