iT邦幫忙

0

Vite+Vue Router發佈至IIS後404錯誤

  • 分享至 

  • xImage

想請教各位一些問題:
在Debug下執行都是正常。
但前後端發佈後,架在IIS上
只有第一頁(Home)正常顯示,其餘(/Page1)都HTTP ERROR 404
請問有哪些地方沒有設定到嗎?
https://ithelp.ithome.com.tw/upload/images/20240730/20168284QMo0KVBoDb.png

vite.config.js :

import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import plugin from "@vitejs/plugin-vue";
import fs from "fs";
const baseFolder =
  // eslint-disable-next-line no-undef
  process.env.APPDATA !== undefined && process.env.APPDATA !== ""
    // eslint-disable-next-line no-undef
    ? `${process.env.APPDATA}/ASP.NET/https`
    // eslint-disable-next-line no-undef
    : `${process.env.HOME}/.aspnet/https`;

// eslint-disable-next-line no-undef
const certificateArg = process.argv
  .map((arg) => arg.match(/--name=(?<value>.+)/i))
  .filter(Boolean)[0];
const certificateName = certificateArg ? certificateArg.groups.value : "vueapp";

if (!certificateName) {
  console.error(
    "Invalid certificate name. Run this script in the context of an npm/yarn script or pass --name=<<app>> explicitly."
  );
  // eslint-disable-next-line no-undef
  process.exit(-1);
}

const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
const keyFilePath = path.join(baseFolder, `${certificateName}.key`);

// https://vitejs.dev/config/
export default defineConfig({   
  plugins: [plugin()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    proxy: {
      "^/weatherforecast": {
        target: "https://localhost:7206/",
        secure: false,
      },    
    },
    port: 5173,
    https: {
      key: fs.readFileSync(keyFilePath),
      cert: fs.readFileSync(certFilePath),
    },
  },
});

router/index.js :

import { createRouter, createWebHistory } from "vue-router";
import Home from "@/components/Page/HomePage.vue";
import Page1 from "@/components/Page/Page1.vue";
export const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      component: Home,
    },
    {
      path: "/Page1",
      component: Page1,
    },   
  ],
});
froce iT邦大師 1 級 ‧ 2024-07-31 09:21:38 檢舉
https://happyhand.github.io/2019/02/14/vue-%E9%9A%A8%E6%89%8B%E7%AD%86%E8%A8%98-IIS-%E6%9E%B6%E8%A8%AD-vue-%E7%AB%99%E5%8F%B0/#%E5%9C%A8-IIS-%E4%B8%AD%E9%85%8D%E7%BD%AE-vue-router

有配置 UrlRewrite 嗎?
沒設定的話,路由這塊還會是IIS去控制,而不是vue-router控制。
因爲你router使用history mode,就必須在IIS設定URL Rewrite導回index,如果是使用hash mode就不需要
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答