Detect router if page was loaded with clearHistory?


#1

Hi, anyone know why routerExtensions.canGoBack(); returns true everytime? Even if I go to page with clearHistory? and routerExtensions.canGoBackToPreviousPage() returns false even if I don’t have this page loaded by clearHistory?


#2

When you load a page with clearHistory set to true both .canGoBack() and .canGoBackToPreviousPage() is going to return false as there won’t be anything visible in back stack. If clearHistory is no set, both will return true then.

I can confirm the above works as expected. There is a open issue with clearHistory only if you are using nested routes but I guess it’s not your case. If you think the above flow is not working as expected, please try to create a playground example.

Also make sure you are accessing canGoBack / canGoBackToPreviousPage once the page / component is finished navigation / ngAfterViewInit , you may not get the right value in a constructor / ngOnInit as the navigation may be still in progress.