Andrii Torzhkov
Andrii Torzhkov

Reputation: 301

Redirect to another page when refreshing the page (F5)

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

Answers (2)

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

Easwar
Easwar

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

Related Questions