For the code examples in the firebase docs, it says to initiate a url rewrite like so:
"hosting": {
// Add the "rewrites" section within "hosting"
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
}
What do I do when I want to pass a parameter to the index page? I tried:
"hosting": {
// Add the "rewrites" section within "hosting"
"rewrites": [ {
"source": "/item/**",
"destination": "/item.html?i=$1"
} ]
}
But that doesn't do anything..
I have also tried the answer below:
"hosting": {
// Add the "rewrites" section within "hosting"
"rewrites": [ {
"source": "/item/:item",
"destination": "/item.html?i=:item"
} ]
}
but that just returns a 404 page.
I know this is an old question but I had a similar issue and didn't find an answer so thought I'd share how I solved it.
{
"hosting": {
// Add the "rewrites" section within "hosting"
"rewrites": [ {
"source": "/item/**",
"destination": "/item.html"
} ]
}
I solved my issue by rewriting the dynamic URL to the static html
page. Since it's a rewrite the URL will stay as the source
URL pattern and not change to the destination
URL like a redirect would.
We can then read the source
URL through window.location.pathname
with Javascript on the item.html
page. You can then use .split('/')
to return an Array to choose the part that you need.
Hope this helps to anybody looking for a similar solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With