Reputation: 301
I have a component to which the transition is carried out using a browsRouter. I need to, when the user tries to refresh the page, redirect him to the login page, how can this be done?
Upvotes: 0
Views: 663
Reputation: 55
UPDATE 2022
The next code is deprecated
window.performance.navigation.type
Now use getEntriesByType:
const entries = window.performance.getEntriesByType("navigation");
if (entries[0].type === "reload") {
// Redirect to login page
}
Upvotes: 0
Reputation: 5402
You can use the Navigation Timing API. Place this in your component constructor :
if (window.performance && window.performance.navigation.type == 1) {
// Redirect to login page
}
Upvotes: 1