本文介绍了渐进式Web应用程序中的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在通知单击时重定向到渐进式Web应用程序中的特定URL,但它不会重定向.
I am trying to redirect to a particular url in progressive web app on notification click but it does not redirect.
情况1:如果未将Web应用添加到主屏幕,则在通知时单击,浏览器窗口打开,并重定向到所需的URL.
Case 1: If the web app is not added to home screen then on notification click the browser window opens up and is redirected to the desired url.
情况2:如果将Web应用程序添加到主屏幕,则登录页面是主页,而不是所需的URL.
Case 2: If the web app is added to home screen then the landing page is the home page and not the desired url.
self.addEventListener('notificationclick', function(event) {
event.notification.close();
event.waitUntil(
clients.matchAll({
type: "window"
}).then(function(clientList) {
console.log(clientList);
for (var i = 0; i < clientList.length; i++) {
var client = clientList[i];
if (client.url == '/' && 'focus' in client)
return client.focus();
}
if (clients.openWindow) {
if (event.notification.tag == 'syncTest') {
console.log(event);
var url = '/#/view-car?start_time=' + getFinalData[0].start_time + '&end_time=' + getFinalData[0].end_time + '&pickup_venue=' + getFinalData[0].pickup_venue;
return clients.openWindow(url);
} else {
var url = '/#/list-venues?start_time=' + getFinalData[0].start_time + '&end_time=' + getFinalData[0].end_time + '&car=' + getFinalData[0].car + '&fuel=' + getFinalData[0].fuel;
console.log(url);
return clients.openWindow(url);
}
}
})
);
});
提前感谢一吨!!
推荐答案
您可以使用类似以下内容的
You can use something like:
if (client.url == 'yourUrl' && 'focus' in client)
return client.focus();
else{
client.navigate('yourUrl').then(function(c){
return c.focus();
});
}
这对我有用.也可以有其他方法.
This worked for me. There can be other ways too.
这篇关于渐进式Web应用程序中的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!