Also, if you are using dash>=2.9.2, be sure to use dcc.Location(refresh="callback-nav") so it will navigate without refreshing the page. More info here:
Another tip is to put the dcc.Location in the app.layout above the dash.page_container - then the forward/back browser buttons will work.