问题
I have a firebase project developed in javscript html and css that works like a social network, i have users in my database and these users have profile information to show.
The problem is, i want to associate each user to a specific URI so everyone can use that link to access a user's info.
Example:
I want to generate a link for users like "https://myproject.com/users/john-doe" (for user john doe) and i want it to bring to that specific user page.
I'm using firebase hosting and there is something for rewriting urls but i couldn't see anything to suit my case, its the intire week i-m looking to solve this problem and still haven't found something yet, please help, thank you!
回答1:
What you're describing is a single-page application, where a single HTML+JavaScript page is handling many URLS - dynamically generating the content.
You'll need to implement multiple steps:
Configure Firebase Hosting to direct multiple incoming URLs to the same HTML page. This is done with a rewrite rule in your
firebase.json
file, such as:"rewrites": [ { "source": "**", "destination": "/index.html" } ]
Now the JavaScript of your
index.html
page can inspect the URL inwindow.location.href
, extract the user name from it, and then serve the correct content for that user.
来源:https://stackoverflow.com/questions/64077469/how-to-create-specific-uris-for-users-in-firebase-web-javascript