I do not understand how to eliminate the following error:

  • go to the site - tyts
  • go to any menu item
  • click the back button in the browser (i use chrome)
  • we get the error:
  • List item

TypeError: Cannot read property 'hasOwnProperty' of null

This error occurs in the main.js script on the site:

if(history.state.hasOwnProperty('url')!=null) 

No matter how I check the url, nothing comes out. Help me to understand!

    1 answer 1

    It would be better to write:

     if(history.state && history.state.hasOwnProperty('url')) 

    hasOwnProperty - returns true or false.

    Now essentially the question: when history is empty, history.state == null. The browser erases and adds to the history of the sequence of transitions. You make one transition to another page, one transition is recorded in the history, go back on the Back button, the browser deletes this transition and the history is empty again.

    • thanks) figured out - sanu0074