我遇到了這個問題:當我在主頁上重新加載 vue 應用程式時,一切正常。當我在另一個子站點上重新加載頁面時,頁面顯示 404。
我在我的專案中使用路由器模塊。我嘗試調整 vue.config.js 并將 publicPath 設定為'/'和''。將其設定為“/”時,我無法在本地復制該問題。當路徑設定為''我在本地和 apache 上得到相同的錯誤。
我嘗試應用一些重定向規則和條件,但我在網上找到的解決相同問題的那些不起作用。
我試圖在我的路由器中使用一個包羅萬象的路由但沒有成功。
有人有類似的問題嗎?謝謝!
路由器
import { createRouter, createWebHistory } from 'vue-router'
const routes = [
{
path: '/',
name: 'home',
component: () => import('../views/Home.vue')
},
{
path: '/contact-imprint',
name: 'contact',
component: () => import('../views/Contact.vue')
}
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
export default router
vue.config.js
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
publicPath: '/',
transpileDependencies: true
})
阿帕奇配置
<VirtualHost *:80>
ServerName domain.io
ServerAlias www.domain.io
ServerAdmin [email protected]
DocumentRoot /var/www/domains/domain/
ErrorLog ${APACHE_LOG_DIR}/error-domain.log
CustomLog ${APACHE_LOG_DIR}/access-domain.log combined
<Directory /var/www/domains/domain/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# my default rewrite cond/rule
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain.io [OR]
RewriteCond %{SERVER_NAME} =www.domain.io
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
# RewriteEngine On
# RewriteBase /
# RewriteRule ^index\.html$ - [L]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule . /index.html [L]
# <ifModule mod_rewrite.c>
# RewriteEngline On
# RewriteBase /
# RewriteRule ^index\.html$ - [L]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule . /index.html [L]
# </ifModule>
</VirtualHost>
uj5u.com熱心網友回復:
如果未啟用
sudo a2enmod rewrite
添加重寫
<Directory /var/www/domain/>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</Directory>
并重新啟動services apache2 restart幫助我解決了這個問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/453533.html
