[SalesForce] LWC Navigation (NavigationMixin) Bug. CurrentPageReference Becomes undefined and won’t navigate

I'm running into a bizarre bug that I can't track down. When using NavigationMixin.Navigate it works just fine MOST of the time. But occasionally, it just stops navigating.

Digging into it as much as I can, it seems like the issue is that currentPageReference is suddenly undefined when the issue presents itself. Also I've noticed that when you call NavigationMixin.GenerateUrl in this problematic state it returns JavaScript:Void(0); instead of the page name, which sort of explains why it isn't going anywhere.

I've tried just setting the this.currentPageReference to a valid value, but that seems to have no effect either. Which probably makes sense since you don't have to import CurrentPageReference to make the navigation mixin navigate, so it must be checking it elsewhere somehow. Also weird because if I put a console.log in the wire method for getting the current page reference, it never fires as changed unless it's being updated to a valid value. When it just becomes undefined that method is never called.

Long story short, I'm seeing an issue that after navigating, pages suddenly have an undefined PageReference. Is there a way to refresh this? Because I noticed if I just refresh my browser after getting into this state then it DOES get the correct PageReference and carries on as expected. Truly odd.

(Also I should clarify, this is within a Community that this is happening)

Best Answer

Wooooow, I finally figured it out. Changing

{ type: 'comm__namedPage', attributes: { pageName: yourPageName } }

to

{ type: 'comm__namedPage', attributes: { pageName: yourPageName, actionName: 'view' } }

fixed it. How? No idea. Did I spend hours on this and am now going to go weep silently in a corner? Yes.

Related Topic