0

I want to use drawer. I wrote the basic code such that when user clicks nav button, the drawer.open is toggled (i.e. true, false, true, false, ...). However, if user goes to other page by clicking a link in drawer menu and comes back by clicking browser's back button, drawer.open is true and user can not click browser's nav button.

  1. User opens the page: drawer.open=false.
  2. User clicks the nav button: drawer.open=true .
  3. User clicks a link in the menu: drawer.open=false in new page.
  4. User clicks browser's back button and comes back: drawer.open=true .

Why is drawer.open=true in 4.? How do I fix this?

  • Try `drawer.open = !drawer.open` instead. See an example at https://stackoverflow.com/questions/52731777/material-components-for-the-web-modal-drawer-example-using-cdns#52769302 – benvc May 01 '19 at 15:43

1 Answers1

0

Reload the page to initialize JavaScript variables when user clicks browser's back button.

<script>
        window.onpageshow = function(event) {
            if (event.persisted) {
                 window.location.reload();
            }
        };
</script>