Blocking Navigation

Explanation

Sometimes, you don't want the user to leave the page. Ideally, this is when leaving the page would cause content to be lost, like a half-filled form, and not becacuse you're running a spam site.

The <Block> component will display a user confirmation that requires user input before navigation will occur.

Live Demo

Use the three buttons at the top of the Sandbox to toggle view modes. Clicking the menu button in the top left corner opens a menu to switch between files.

On GitHub

If you want to run this code locally, the source code is available on GitHub here.