AngularJS $location's history feature allows for easy navigation between previous

Imagine the user clicks on a link like this:

account/organisations/organisation1/news/21

After that, I use $location.path(url) to redirect the user from the startpage (news/today) to the specified page. But when the user tries to go back using the back button, they are taken back to news/today instead of

account/organisations/organisation1/news/

I attempted to split the URL and manipulate the history in order to achieve the desired behavior:

var url = "account/organisations/Vereinsplaner/news/21".split("/");
var curUrl = "";
var part;
while(part = url.shift()){
     curUrl = curUrl+"/"+part;

     $location.url(curUrl);
     $location.replace();
     $window.history.pushState(null, 'any', $location.absUrl());
 }

Context: This link is received through PushNotification in an Ionic App. When the user taps on it, they are redirected to the subpage but face issues navigating back due to lack of proper history.

Answer №1

Utilize the $state.go() function over $location in IONIC as it utilizes UI-ROUTER, making it the recommended method for redirection and registering previous states...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Developing a search feature with Mongo and NodeJS

Currently, I've been immersed in teaching myself the ropes of a MERN CRUD project. However, I have yet to tackle the front end side of things. On the backend, I have successfully implemented all basic CRUD functionalities with the API. My current hurd ...

Regular expressions are compatible with JavaScript, but unfortunately, they are not supported

After successfully implementing this regex in my JavaScript for webpage validation, I attempted to incorporate it into my PHP script as a backup. However, every string I passed through the regex failed, even correct names. In an effort to resolve the issu ...

Having trouble extracting the date modified from a JSON file

I am able to retrieve section name, URL, web title, and headline from parsing JSON data with this code snippet. However, I seem to be encountering an issue where I cannot extract the last modified date. Here is the JSON structure: { "response":{ ...

Map Infobox appearing on page load

I am working on a Google map project where markers and info boxes dynamically populate when the user clicks on the map. However, I now need the info box to be loaded initially when the map loads, without requiring a click event. I have tried writing some c ...

Slide in parts gradually by scrolling up and down, avoiding sudden appearance all at once

I have implemented a slider on my website using jQuery functions. For scrolling down, the following code snippet is used: jQuery("#downClick").click(function() { jQuery("html, body").animate({ scrollTop: jQuery(document).height() }, "slow"); ...

Is it possible for the `findIndex` method in EcmaScript6 to return multiple values at once

When delving into ES6, I came across a situation where I needed to find the index of multiple items in an Array. However, I found that it only returned the index of the first item that matched my condition or callback function. For example, let's say ...

Tips for populating all the ionic form fields using speech recognition technology

In the process of developing an Ionic 4 application, I am faced with a challenge where I need to fill in multiple form fields using the Ionic speech-recognition plugin. Currently, I am only able to populate one field at a time. What I am looking for is a w ...

Vue - Issue with reading properties of undefined while dropping a file

Trying to drag and drop an mp3 file into a dropbox on my website is proving challenging. Each time I test it, no matter the file I drop, the same error persists: Uncaught TypeError: Cannot read properties of undefined (reading 'files') Below is ...

Issue with DWR and Android web browser

I recently encountered an issue while trying to access an application through the Android browser. The application uses DWR to maintain connections with connected clients. Everything seems to be working fine, except for the fact that if there is a 2-minut ...

Tips on completing landing page animations and displaying the main page of a website by utilizing React JavaScript

https://i.stack.imgur.com/M4VgY.pngIs there a way to stop the landing page animation after 2-3 seconds and show the main page instead? Can I achieve this by using setTimeOut function in JavaScript? [ export default Loader; ...

Is it possible to populate an empty list of objects within the Page_Load scope after the page has finished loading?

I am facing a challenge where I need to populate the list var docfiles = new List<string>(); with file names uploaded by the user using dropzone js. However, the list remains empty because when the page loads for the first time, httpRequest.Files.C ...

whenever I execute my `node file.js 1 23 44` command, nothing is displayed on the screen

When I execute node file.js 1 23 45, the expected output is supposed to be One TwoThree FourFive. However, for some unknown reason, nothing is being printed out. The script appears to run without any errors, but the desired output is just not appearing. ...

javascriptDOM selectors document object

When selecting elements in my HTML page, I often find myself wondering why I always have to use the "document" keyword. For example: //variable body var content = document.getElementsByTagName("body"); Why can't I simply get all p tags from bo ...

What distinctions can be made between Controlled and Uncontrolled Components when using react-hooks-form?

Trying out the React Hooks form, I came across some interesting concepts like controlled and uncontrolled forms. Controlled Form <form onSubmit={handleSubmit(onSubmit)}> <input name="firstName" ref={register({ required: true })} /> ...

angularjs - user-defined attribute turns blank

I'm having an issue when trying to unshift an object into an existing array list in AngularJS. After doing so, one of the values becomes empty. What is the correct way to add a new object to an existing array in AngularJS? Here's my code: var ...

What is the process for converting this Greasemonkey code to JavaScript specifically for Android devices?

Having trouble loading a page and running a JavaScript code on it? Don't worry, you're not alone. I came across a Greasemonkey script that does the trick, but now I'm struggling to make it work on Android. It's probably because of my la ...

Transform the date format from yyyy-MM-dd'T'HH:mm:ss.SSS'Z' to dd-mmm-yyyy with the help of JavaScript

I am looking to convert date format from yyyy-MM-dd'T'HH:mm:ss.SSS'Z' to dd-mmm-yyyy when the dates are retrieved from a JSON object. Currently, I am utilizing the ng-csv plugin to download this JSON data, which is working properly. How ...

Exploring the depths of JSON using @attributes and @association in the realm of JavaScript and AngularJS

Currently, I am working on a project that involves utilizing an API for data retrieval, updates, and deletions. The API in question is the prestashop API. While I have managed to retrieve data and update certain items successfully, I encountered an issue. ...

Express.js Issue: Error in JSON Object Returned When Date Parameter is Empty

Currently tackling the challenges of the FreeCodeCamp Timestamp Microservice project and facing a roadblock in the implementation. While most requirements are met successfully, there's an issue with handling an empty date parameter test case. Let me b ...

Creating a streamlined real-time application using the powerful combination of Django-swampdragon and AngularJS

Currently, I am using django-swampdragon along with angularjs to develop a simple Django application that displays website requests in real-time. While the Django part of the logic seems to be functioning correctly, I encounter issues when attempting to m ...