我想要任何流量:
mysite.com/suppliers/add-supplier
在我的組態檔add-supplier.html
中標識路徑時被定向到。firebase.json
我試過這個:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"redirects": [
{
"source": "/suppliers/add-supplier",
"destination": "/add-supplier.html"
}
],
"cleanUrls": true
},
"storage": {
"rules": "storage.rules"
}
}
即使這可以正確識別和重定向,它也會擺脫suppliers/add-supplier
路徑并使其成為mysite.com/add-supplier
有沒有辦法在保留原始 URL 的同時重定向到正確的 HTML 頁面?
uj5u.com熱心網友回復:
你有兩個選擇:
- 使用重寫而不是重定向:
"rewrites": [
{
"source": "/suppliers/add-supplier",
"destination": "/add-supplier.html"
},
{
"source": "**",
"destination": "/index.html"
}
]
- 完全洗掉重定向,并將檔案放在
suppliers/add-supplier.html
而不是根目錄中
uj5u.com熱心網友回復:
我將@samthecodingman 的答案與一些更改結合起來并使其正常作業:
將頁面移動到新目錄
我將add-supplier.html
檔案移動到公共目錄內的一個新檔案夾suppliers
中,以便它suppliers/add-supplier.html
firebase.json:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
},
{
"source": "/suppliers/add-supplier",
"destination": "suppliers/add-supplier.html"
}
],
"cleanUrls": true
},
"storage": {
"rules": "storage.rules"
}
}
這將正確加載頁面,但無法識別 CSS、媒體和 JS 檔案。要解決此問題,請將所有資源檔案更改為../
在前面:
更改前:<link href="dist/css/style.css" rel="stylesheet" type="text/css">
更改后:<link href="../dist/css/style.css" rel="stylesheet" type="text/css">
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/505229.html
標籤:Google Cloud Collective 火力基地 firebase 托管
上一篇:我在firebase中的'onValue'語法和'set'語法之間連接時遇到問題
下一篇:在社交應用中獲取用戶資料