6

uni-app开发到部署指南 - 搞搞震

 3 years ago
source link: https://www.wujingquan.com/posts/6fc00cce.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

部署到H5刷新404问题

// App.vue

onLaunch() {
  // #ifdef H5
  if (e.path == undefined) {
    uni.redirectTo({
      url: '/pages/index/index'
    });
  }
  // #endif
}
// 导航栏组件

<template>
  <view @click="goBack">返回</view>
</template>

<script>
  export default {
    methods: {
      goBack() {
        // #ifdef H5
        const pages = getCurrentPages()
        if (pages.length > 1) {
          uni.navigateBack();
        } else if (!window.document.referrer.length) {
          uni.redirectTo({
            url: '/pages/index/index'
          });
        } else {
          history.back()
        }
        // #endif

        // #ifndef H5
        uni.navigateBack();
        // #endif
      }
    }
  }
</script>
# Nginx
# https://router.vuejs.org/guide/essentials/history-mode.html#nginx

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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK