3***@qq.com
3***@qq.com
  • 发布:2024-07-23 15:09
  • 更新:2025-01-21 23:21
  • 阅读:214

H5发布到前端网页托管,用的支付宝云的正式版空间,不支持History

分类:uni-app

打开线上H5网站一片空白。打包目录设置成/h5/也没有用,是不是支付宝云托管空间,不支持 历史模式?

2024-07-23 15:09 负责人:无 分享
已邀请:
3***@qq.com

3***@qq.com (作者) - xiao bia

就是下面的图片配置

l***@163.com

l***@163.com

解决了吗?我也遇到这样的问题

骑猪o0o找牛

骑猪o0o找牛 - 一挖一麻袋

3***@qq.com

看了一下 支付宝云的处理, 当访问时, 它 居然 返回的 是 302 , 然后 重定向到了 xxxx.com/index.html ...

并不是 找不到资源的时候 , 返回 index.html的 内容

而是 重定向 到 了 xxxx.com/index.html ...

导致 vuerouter 找不到 对应的路由, 因为 location.path = "index.html"

我现在 简单的处理是 :

if (window.location.pathname === '/index.html') {

window.history.replaceState({}, '', '/');

}

假设访问的 是 ccdxd.com, 支付宝云 返回302, 重定向到 ccdxd.com/index.html

我们前段的代码 执行,

然后

if (window.location.pathname === '/index.html') {

window.history.replaceState({}, '', '/'); // 这里 url 再次变成 ccdxd.com

}

vuerouter 匹配到 路由 , 展示我们的 页面...

  • 3***@qq.com (作者)

    谢谢大神解答 ,在哪里改代码?

    2025-01-23 15:55

  • 骑猪o0o找牛

    回复 3***@qq.com: 在设置router前就可以, 它是通过一个 插件来设置的router, app.router = router


    import { createSSRApp } from "vue";  
    import App from "./App.vue";

    if (window.location.pathname === "/index.html") {
    window.history.replaceState({}, "", "/");
    }
    export function createApp() {
    const app = createSSRApp(App);
    Object.defineProperty(app, "router", {
    set(v) {
    console.log("这里可以找到 插件 设置 router的地方");
    },
    });
    return {
    app,
    };
    }

    2025-02-04 18:54

要回复问题请先登录注册