Hash

  1. location ^~ /路径名 {
  2. try_files $uri $uri/ /路径名/index.html;
  3. }

History

普通域名正常解析

  1. location ^~ /tw {
  2. index index.html index.htm;
  3. try_files $uri $uri/ /tw/index.html;
  4. }

前端路由控制

  1. const router = createRouter({
  2. history: createWebHistory(import.meta.env.VITE_ROUTER_URL),
  3. routes,
  4. });
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import path from "path";
  4. import Components from "unplugin-vue-components/vite";
  5. import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
  6. const pathSrc = path.resolve(__dirname, "src");
  7. export default defineConfig({
  8. base: process.env.NODE_ENV === 'development' ? '/' : './',
  9. resolve: {
  10. alias: {
  11. "@/": `${pathSrc}/`,
  12. },
  13. },
  14. plugins: [
  15. vue(),
  16. Components({
  17. resolvers: [NaiveUiResolver()],
  18. }),
  19. ],
  20. });

子域名重定向

image.png