azure - 使用历史记录模式在 Azure 应用服务上部署 Vue CLI

标签 azure vue-router azure-web-app-service vue-cli-3 html5mode

您好,有谁已将应用程序部署到 azure 应用程序服务并让历史记录模式正常工作吗? 我一直在尝试打开和关闭,但无法使其工作:S

我使用 connect-history-api-fallback ,我的 package.json 看起来像这样:

{
  "name": "wbo",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "start": "node server.js"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "buefy": "^0.7.3",
    "connect-history-api-fallback": "^1.6.0",
    "express": "^4.16.4",
    "js-cookie": "^2.2.0",
    "lodash": "^4.17.11",
    "nprogress": "^0.2.0",
    "vue": "^2.6.6",
    "vue-router": "^3.0.1",
    "vuelidate": "^0.7.4",
    "vuex": "^3.0.1",
    "vuex-persistedstate": "^2.5.4"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.5.0",
    "@vue/cli-plugin-eslint": "^3.5.0",
    "@vue/cli-service": "^3.5.0",
    "@vue/eslint-config-prettier": "^4.0.1",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.8.0",
    "eslint-plugin-vue": "^5.0.0",
    "node-sass": "^4.9.0",
    "sass-loader": "^7.1.0",
    "vue-cli-plugin-buefy": "^0.3.5",
    "vue-template-compiler": "^2.5.21"
  }
}

我在根目录中有一个 server.js 文件,如下所示:

const express = require('express')
const history = require('connect-history-api-fallback')
const port = process.env.PORT || 8080
const app = express()

app.use(history())

app.use(express.static(__dirname + '/dist/'))
app.get('/*', function(req, res) {
  res.sendFile(__dirname + '/dist/html.html')
})
app.listen(port)

console.log('Server started....')

有谁知道我是否还需要做一些事情,或者可以在某处看到问题:S

最诚挚的问候丹尼尔

最佳答案

我使用 ISS 服务器

这是我的代码

  <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                     <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
                       <match url="(.*)" />
                      <conditions logicalGrouping="MatchAll">
                         <add input="{​​​​​​​REQUEST_FILENAME}​​​​​​​" matchType="IsFile" negate="true" />
                         <add input="{​​​​​​​REQUEST_FILENAME}​​​​​​​" matchType="IsDirectory" negate="true" />
                      </conditions>
                      <action type="Rewrite" url="/" />
                    </rule>
    
    
                    <rule name="redirect all requests" stopProcessing="true">
                        <match url="^(.*)$" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{​​​​​​​REQUEST_FILENAME}​​​​​​​" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
                         </conditions>
                        <action type="Rewrite" url="index.html" appendQueryString="true" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

我使用相同的文档,但我不知道是否还有更多我需要做的事情,或者可以在某处看到问题

关于azure - 使用历史记录模式在 Azure 应用服务上部署 Vue CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55246212/

相关文章:

c# - 如何使用 Azure 资源管理 api 按资源类型和资源组获取资源列表

vue.js - VueRouter this.$route.query 总是空的

vue.js - 如何访问其中包含连字符的 URL 查询 vue js

reactjs - 管理 Azure 静态网站的 HTTP header

azure - 用户对使用 Azure AD 保护的 Web 应用程序的访问/授权

asp.net-core - Web App 进程重新启动故障排除

authentication - Azure Multi-Tenancy 应用程序

spring - Karate如何在Azure管道中启动应用程序?

azure - Get-AzureVM 不显示虚拟机

javascript - Vue router 路由的安全性