Reloading the Angular application returns it to its initial state

I am currently developing a Dashboard using AngularJS. I am utilizing ui.router to generate states from a JSON file named `pages.json`. Even though my app is functioning properly, I am facing an issue where refreshing the page with the URL "localhost:#/map" redirects me to the state of "localhost:#/dashboard". How can I ensure that the state matches the URL entered by the user?

var $urlRouterProviderRef = null;
var $stateProviderRef = null;

myApp.run(function ($q, $rootScope, $state, $http, navbars) {
    navbars.load();
    
    $http.get("js/config/pages.json")
        .success(function (data) {
            angular.forEach(data, function (value, key) {
                var state = {
                    "url": value.url,
                    "templateUrl": value.templateUrl,
                    "controller": value.controller
                };
                $stateProviderRef.state(value.sref, state);
            });
        });
});

myApp.config(function ($stateProvider, $locationProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/dashboard');
    $urlRouterProviderRef = $urlRouterProvider;
    $stateProviderRef = $stateProvider;
})

pages.json

[
{
    "displayname": "Dashboard",
    "active": true,
    "name": "dashboard",
    "sref": "dashboard",
    "url": "/dashboard",
    "controller": "layoutOneCtrl",
    "templateUrl": "views/dashboard.html",
    "icon": "fa-dashboard",
    "children": [{
        "name": "dashboard"
    }]
}, {
    "displayname": "Map",
    "open": false,
    "active": false,
    "name": "map",
    "sref": "map",
    "url": "/map",
    "templateUrl": "views/layout1.html",
    "controller": "layoutOneCtrl",
    "icon": "fa-map-marker",
    "children": [{
        "name": "map"
    }]
}
.
. 
.
]

Answer №1

Each time the page is refreshed, the run function is triggered to retrieve the value from pages.json. To ensure this value persists, you must either update the pages.json file or store the URL value in local storage or session storage. By doing so, you will be able to access the URL value from local storage or session storage whenever the page is refreshed.

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

The definition of Csrftoken is missing

The code I am currently using, as per the recommended documentation, is: function csrfSafeMethod(method) { // these HTTP methods do not require CSRF protection return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); ...

Is it possible for the original object to be altered when passing it as a parameter to a function in a different file?

When you update an object passed as a parameter, will the updates be reflected "upwards" if the method receiving the parameter is in a different file? Or will the object retain its own context despite being passed down? ...

How can I access this document using Java?

Can someone assist me in retrieving JSON body documents like this from MongoDB? { "question":"what is your favorite color?", "choices":[{"option":"yellow"},{"option":"blue"},{"option":"green"}], "creation-date":"2014-04-13", "expiry date":"2014-04-14" } ...

Numerous objects come into view as you scroll

I found a code snippet online that animates items as they appear on scroll. However, the code only triggers animation for one item at a time. How can I modify the code to trigger the animation for all items? const observer = new IntersectionObserver(e ...

Streamline the testing process to ensure compatibility with jQuery version 2.x

I currently have a substantial JavaScript code base that is all built on jQuery 1.8. I am planning to upgrade to jQuery 2.1 in the near future and I am fully aware that many parts of my code will likely break during this process. Is there any efficient me ...

How to retrieve the column names of a table using Web SQL?

Working on extracting column lists from Web SQL (Chrome's local database). One approach is to gather information from sqlite_master. SELECT name, sql FROM sqlite_master WHERE type="table" AND name = "'+name+'"; As an example, here is a sam ...

Eliminating unique phrases from text fields or content sections with the help of jQuery or JavaScript

I'm currently working on a PHP website and have been tasked with the responsibility of removing certain special strings such as phone numbers, email addresses, Facebook addresses, etc. from a textarea that users input data into. My goal is to be able ...

Issues with Internet Explorer cutting off flashVars that include JSON data

This issue is exclusive to Internet Explorer. My setup involves the use of swfobject to load flash vars in the following manner: var flashVars = { myVar:'{"url":"http://google.com/", "id":"9999"}', }; var params = { allowFullScreen:" ...

What is the best way to enforce a required selection from one of the toggle buttons in a React form?

Is there a way to require the user to click one of the toggle buttons in a react form? I need to display an error message if the user submits the form without selecting a button. I tried using the "required" attribute in the form but it didn't work. H ...

Designing a dynamic carousel with AngularJS

Currently facing an issue with handling JSON data in AngularJS. When I select the 'img' object, it logs to the console but doesn't get applied to the scope. Can anyone provide some guidance on this? 'use strict'; angular.module(& ...

A step-by-step guide on decoding JSON data received from the tweepy API

After researching how to scrape tweets using tweepy, I came across a solution based on the first answer of this question. The code provided is as follows: consumer_key = "" consumer_secret = "" access_token = "" access_token_secret = "" import tweepy au ...

Tips for adjusting the up and down controls and spins of a date input after modifying its height

After adjusting the height of my inputs (date type) to 40px, I noticed that the up and down controls are no longer aligned with the text inside the field. I am looking for a solution to either adjust the height of the spins or remove them if necessary in ...

Creating an If statement to evaluate the state of a parameter

In my simple Graphics User Interface, when the user clicks on "move", a yellow rectangle div moves across the screen. Now, I am trying to implement an event based on the position of the rectangle on the page. For example, if the div is at 400px (right), t ...

Having difficulty locating audio files within a Next.js project

I am facing challenges when trying to import my audio files into a redux slice. Currently, I am attempting to retrieve my audio files from the app > public > audio directory. I have made efforts to access my audio files through 2 different director ...

The function for the Protractor promise is not defined

UPDATE: After some troubleshooting, I believe I have identified the issue causing it not to work. It seems that I am unable to pass arguments along when calling flow.execute(getSpendermeldung). Does anyone have a better solution than wrapping the ApiCall i ...

Enhancing the user experience of the dropdown component through improved

I have developed an accessibility feature for a dropdown component that dynamically populates values in the options menu only when the dropdown is opened. This means that it compiles the template on the fly and attaches it to the dropdown box. Dropdown HT ...

Waiting for the HTTP response in NodeJS before sending the next request

I'm currently struggling with my NodeJS code. I am attempting to send an HTTP Request to a REST API, which will respond with a new URL. Once I receive this URL, I need to make another request to that specific URL and continue the process. My current ...

What sets apart gzip from x-gzip content? And how can I decompress x-gzip specifically? zlib appears to be struggling

One of my npm libraries, named "by-request", has the ability to auto-decompress web content. A snippet of code from this library that handles auto-decompression is shown below: if (!options.dontDecompress || !binary) { if (contentEncoding ...

Talend Open Studio encountered a POST request error stating: "Incomplete form input: grant_type."

I have encountered an issue while using Talend Open Studio to make a POST request to the Commerzbank API in order to obtain a refresh token. The error message "Missing form parameter: grant_type" is appearing, even though my tREST component setup looks lik ...

How to Convert JSON from an Object to a String using jQuery?

Currently, I am utilizing the Ajax Form jQuery plugin to fetch JSON data from a server: /** * A convenient function for the jQuery AJAX form plugin. */ function bindOnSuccess(form, callback) { form.ajaxForm({ dataType: 'json', ...