Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript firebase.auth().onAuthStateChanged()函数即使在取消订阅后也会被多次调用_Javascript_Firebase Authentication - Fatal编程技术网

Javascript firebase.auth().onAuthStateChanged()函数即使在取消订阅后也会被多次调用

Javascript firebase.auth().onAuthStateChanged()函数即使在取消订阅后也会被多次调用,javascript,firebase-authentication,Javascript,Firebase Authentication,您说两个HTML页面运行的脚本相同。因此,当您重定向到任一页面时,代码将再次运行,试图再次重定向您 如果这确实是问题所在,那么快速修复方法可能是传递一个查询参数,如redirect=true,然后仅在该参数为false时执行代码 window.location.replace(“library.html?redirect=true”) 然后用正则表达式f.e解析你的url const wasRedirected = new Regex(/[?&]redirect=(true|false)


您说两个HTML页面运行的脚本相同。因此,当您重定向到任一页面时,代码将再次运行,试图再次重定向您

如果这确实是问题所在,那么快速修复方法可能是传递一个查询参数,如
redirect=true
,然后仅在该参数为false时执行代码

window.location.replace(“library.html?redirect=true”)

然后用正则表达式f.e解析你的url

const wasRedirected = new Regex(/[?&]redirect=(true|false)/g).exec(window.location)[1] === 'true'
函数的作用是:在auth对象上设置一个观察者。作为观察者,它不断检查授权状态。这就是index.html页面不断重新加载的原因。解决方案是在第一次重新加载窗口时只调用一次onAuthStateChanged()函数。在index.js文件中添加以下代码

window.onload = unSubscribe;


希望能有所帮助。

可能就是这样!你能告诉我如何通过查询参数重定向吗?对不起,我是webdevelopment的新手,所以如果你能告诉我它仍然以同样的方式运行,没有任何改进!“”保持加载多次使用window.location.href=“hostel.html”解决问题;在index.js文件中的if(user!=null)条件中,为index和library分别维护两个不同的.js文件。