我在 Vue 中有一個路由器,如下所示:
{
path: '/temporaryList/:tempUrl',
name: 'temporaryList',
component: () => import('../views/TemporaryListView.vue')
}
我想為“tempUrl”-param 發送一個值,例如看起來像這樣:(
https://www.amazon.se/[n[test[~[
這個值來自 encodeURIComponent() 函式,所以它應該能夠在 URL 中使用)
由于某種原因,這似乎不起作用,當我嘗試訪問此頁面時,我得到:
"There was no web page at the URL: http://localhost:3000/temporaryList/https://www.amazon.se/[n[test[~[ "
我已經用 node 構建了這個完全相同的解決方案,并表達了這似乎不是問題的地方。不知道我發送的param的值是不是對Vue來說太長了?例如,當引數包含“%”時,Vue 似乎也不喜歡。
有什么方法可以讓 Vue 路由器允許這種型別的引數值?
uj5u.com熱心網友回復:
Vite 在請求 URL 上使用了 decodeURIComponent 函式。我發送的引數值中包含“%”,這使得 Vite 將每個“%”讀取為“/”。這使得 Vite 搜索了一個不存在的位置。
這個 npm-package 解決了我的問題:https ://github.com/ivesia/vite-plugin-rewrite-all
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/488439.html
