uni-app开发到部署指南

部署到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;
}