Search code examples
firebasehttp-redirectprogressive-web-appsfirebase-hosting

Firebase, url with variables redirects to main page


I have a link that looks like this:

https://mywebsite.com/#/new-account?jk=-LOLgLiyfxANW-ojMKrf

jk is the variable that I would like to read and use on this page. The variable will change for each user.

The problem is that when this link is clicked, the user is redirected to the main page of the application. The app is a PWA developed using Ionic. I checked my code carefully and there is nothing that would cause such redirect behavior.

So far I tried uploading the app again with deselecting "single page" option during Firebase Init but the problem persists.

thanks


Solution

  • I contacted firebase support and they suggested I solve it by including this in firebase.json within the hosting tag:

    "redirects": [{
    "source": "/#/new-account?:vars*",
    "destination": "https://mywebsite.com/#/new-account?:vars*",
    "type": 301
    }]
    

    Firebase hosting captures whatever text is after : and transfers it to the destination. Otherwise, it creates a 404 for any link that doesn't exactly match the URL of existing pages.

    Maybe there is a more elegant way to do this but it worked well for my situation. More info is available at this link: https://firebase.google.com/docs/hosting/full-config#redirects