Back button for different custom states

Hello. I am having trouble navigating backwards in a multi-state application.
I can go to a article from the profile state, search state and from the article feed state.
How to return to the state from which I got to the article

I found such a thread Go back functionality in native app design on the forum but did not understand how to implement it in practice.