Using navigate function outside of app context

Hi,

At this moment in my app, for all API related functions I’m using a file called api.js. Within my page components I simply import the methods so I can then interact with all the methods inside this file.

This works great.

However, when an API call returns an 403 (unauthorized) message, I would like to have the app navigate to my login page. I would like to handle this inside my api.js, so it is taken care of within the entire app.

Is there a way to access the app router function from such a file?

You can just assign it to global var in the place where you init it, e.g. to window.f7

1 Like