OnInit method is not getting called again when navigating back and forth from a view in SAPUI5

You have identified the correct use case as it is by design as you have navigated back and forth, it renders the last version rendered and OnInit() does not gets called. But if you want to override this behavior, SAP lets you do it.

You can delegate to the patternMatched event of router, so that wheever the view is rendered the OnInit() method is invoked.

this.getOwnerComponent().getRouter().getRoute("<Route name>").attachPatternMatched(<Your Handler>, this);

You need to attach the even handler to the router in the init method of the controller. Hope it helps and sorts out your requirement.

Updated on: 17-Feb-2020


Kickstart Your Career

Get certified by completing the course

Get Started