Conditions not working to navigate the pages