如何在FIREBASE WEB javascript中为用户创建特定的URI [英] How to create specific URIs for users in FIREBASE WEB javascript
问题描述
我有一个用javscript html和css开发的firebase项目,其工作方式类似于社交网络,我的数据库中有用户,这些用户可以显示个人资料.
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.
问题是,我想将每个用户都关联到特定的URI,以便每个人都可以使用该链接来访问用户的信息.
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.
示例:
我想为诸如"https://myproject.com/users/john-doe"之类的用户生成一个链接. (针对用户john doe),我希望它带到该特定用户页面.
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.
我正在使用Firebase托管,并且有一些可以重写url的内容,但我找不到适合我的情况的内容,这是我打算解决该问题的第一周,但仍然找不到任何内容,请帮忙,谢谢!
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!
推荐答案
您所描述的是一个单页应用程序,其中一个HTML + JavaScript页面正在处理许多URL-动态生成内容.
What you're describing is a single-page application, where a single HTML+JavaScript page is handling many URLS - dynamically generating the content.
您需要执行多个步骤:
-
配置Firebase托管以将多个传入URL定向到同一HTML页面.这是通过
firebase.json
中的rewrite
规则完成的文件,例如:
Configure Firebase Hosting to direct multiple incoming URLs to the same HTML page. This is done with a
rewrite
rule in yourfirebase.json
file, such as:
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
现在index.html
页面的JavaScript可以检查window.location.href
中的URL,从中提取用户名,然后为该用户提供正确的内容.
Now the JavaScript of your index.html
page can inspect the URL in window.location.href
, extract the user name from it, and then serve the correct content for that user.
这篇关于如何在FIREBASE WEB javascript中为用户创建特定的URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!