Facing problem with hardware back button in ionic


I have created a dynamic routing pages with states. for eg : modules.login, modules.dashboard.
I saw solutions which say that hardware back button works for sectionA to sectionB states, not for section.sectionA to section.sectionB (i.e inner routes). I tried alert in ionic.bundle.js where registerbackbutton and onhardwarebackbutton codes are written it never gets called, tried document.ready code also doesn’t work.
Can someone tell the exact reason for not working and solution for the same.