uniapp 404页面、打包index.html 没有引号

一、需求:uniapp 在写 H5 时,如果在地址栏乱输入,会跳转到 404 页面。

思路:uniapp 有个 应用生命周期 onPageNotFound,让跳转不存在的页面时会执行这个回调函数。所以需求就很好解决了!

具体操作:

第一步:写一个 404 页面,并在 pages.json 中配置其路由。

第二步:在 App.vue 的 onPageNotFound 生命周期中处理跳转到 404 页面的逻辑:

复制代码
onLaunch: function() {
            console.log('App Launch')
            // uni.hideTabBar();
            // #ifdef APP-PLUS
                
            // #endif
        },
        onPageNotFound() {
            uni.switchTab({
                url: '/pages/tabBar/home/home'
            })
        },
        onShow: function() {
            
        },
复制代码

二、UNI-APP 框架中解决打包后index.html文件中没有引号问题

  1. 在项目根目录下添加文件vue.config.js。
  2. 在文件中添加如下内容:
    复制代码
    module.exports = {
        chainWebpack: config => {
         const html = config.plugin('html-index');
         html.tap(args => {
             args[0].minify.removeAttributeQuotes = false;
             return args;
         })
        },
    }
    复制代码

    修改mainfest.json

     "h5" : {
        ...,
        "router" : {
            "base" : "./"
        },
    }

     

posted @   haonanElva  阅读(394)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示