TechQA.

How to reload the same page on browser refresh in angularjs

508 views Asked by Araf At 2020-03-01T06:42:09+00:00 01 March 2020 at 06:42 2025-12-06T14:06:12+00:00

I've a nav bar and when I click any tab in the nav bar, it takes me to that tab.

<section id="tabs">
    <div class="mob-nav"> 
        <div class="nav nav-tabs nav-fill nav-tabs-scroll" id="nav-tab" role="tablist"> 
            <!-- N add new class nav-tabs-scroll -->
            <a class="nav-item nav-link" style="padding-top: 10px;"
               ng-class="{ active: $index == 0 }"
               id="nav-{{menuTab.menuURL}}-tab"
               data-toggle="{{menuTab.dataToggle}}"
               data-target="#{{menuTab.menuURL}}"
               href="#{{menuTab.menuURL}}" role="tab"
               aria-controls="nav-{{menuTab.menuURL}}"
               ng-repeat="menuTab in menuList">
            </a>
        </div>
    </div>
</section>
<!-- Tab Details -->
<section id="tabs">
    <div class="">
        <div class="">
            <div class="mb-d-150">
                <div class="tab-content py-3 px-sm-0 pl-0 pr-0"
                     id="nav-tabContent"> 
                    <!-- N removed py-3 class -->
                    <div class="tab-pane fade show"
                         ng-class="{ active: $index == 0 }"
                         id="{{menuTab.menuURL}}" role="tabpanel"
                         data-target="#{{menuTab.menuURL}}"
                         aria-labelledby="nav-{{menuTab.menuURL}}-tab"
                         ng-include="menuTab.colDef"
                         ng-repeat="menuTab in menuList">
                    </div>
                    <div class="tab-pane fade" id="changepass" role="tabpanel"
                         aria-labelledby="nav-about-tab"
                         ng-include="changePasswordTemplate">
                    </div>
                </div>    
            </div>
        </div>
    </div>
</section>

Here's an example of menuList.

[{
    menuID: "USER LANDING PAGE"
    caption: "Dashboard"
    parent: "root"
    menuURL: "exampleModal"
    cssClass: "fas fa-cog fa-lg"
    cssParent: "nav navbar-nav"
    aClass: "customerLandingPageTemplate"
    SlNum: 98
    colDef: "/js/templates/user-landing-page.html"
    menuList: []
    dataToggle: "modal"
},{
    menuID: "USER QUERIES"
    caption: "USER QUERIES"
    parent: "root"
    menuURL: "user-queries"
    cssClass: "fas fa-comment-alt fa-lg"
    cssParent: "nav navbar-nav"
    aClass: "userQueriesTemplate"
    SlNum: 100
    colDef: "/js/templates/user-queries.html"
    menuList: []
    dataToggle: "tab"
}]

Here's the angularjs part which gives me the menuList:

GetData.async(CONFIG.urlMaker('ws/menulist?userid=' + userid)).then(function (data) {
    $scope.menuList = data;
    console.log($scope.menuList)
});

When I refresh browser, it always takes me back to the USER LANDING PAGE no matter where I refresh. But on browser refresh, I need to reload the page where I was before refreshing.

html angularjs browser browser-refresh
Original Q&A
1

There are 1 answers

0
eustatos eustatos On 2020-03-01T13:15:56+00:00 01 March 2020 at 13:15

You could use the session storage for saving the last state. Internal code snippet does not allow to use session storage. A working example on JSBin.

angular.module('app', ['ui.router'])
  .config(($stateProvider) => {
    const helloState = {
      name: 'hello',
      url: '/hello',
      template: '<h3>hello world!</h3>'
    }

    const aboutState = {
      name: 'about',
      url: '/about',
      template: '<h3>Its the UI-Router hello world app!</h3>'
    }

    $stateProvider.state(helloState);
    $stateProvider.state(aboutState);
  })
  .run(($state, $transitions) => {
    $transitions.onSuccess({}, transition => {
      sessionStorage.setItem('lastState', transition.to().name);
    });
    const lastState = sessionStorage.getItem('lastState');
    if (lastState) {
      $state.go(lastState);
    }
  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.9/angular.min.js"></script>
<script src="//unpkg.com/@uirouter/angularjs/release/angular-ui-router.min.js"></script>

<body ng-app="app">

  <a ui-sref="hello" ui-sref-active="active">Hello</a>
  <a ui-sref="about" ui-sref-active="active">About</a>

  <ui-view></ui-view>
</body>

Related Questions in HTML

  • How to store a date/time in sqlite (or something similar to a date)
  • How to use custom font during html to pdf conversion?
  • Storing the preferred font-size in localStorage
  • mp4 embedded videos within github pages website not loading
  • Scrimba tutorial was working, suddenly stopped even trying the default
  • Is there any way to glow this bulb image like a real light bulb
  • With non-graphical maps in Leaflet, zoomDelta doesn't work
  • What can I do to improve my coding on both html and css
  • Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
  • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
  • Displaying a Movie List on a Website Using Jinja2 and Bootstrap
  • How to redirect to thank you page after submitting a Google form embedded into a Google Site?
  • Storing selected language in localStorage
  • Fences (parenthesis, braces) in HTML and MathML
  • Understanding Scroll Anchoring Behavoir

Related Questions in ANGULARJS

  • How to automatically change path in angular when scrolling
  • Error two clicks to be able to login Angular 16
  • Passing an array of objects through the $http.post method in angular JS does not work
  • Understanding how to apply Angular Signals from beginning on an existing service
  • provider duplicate while compiling a Cordova application for the Android platform
  • How can I use angularjs $parse service in Angular?
  • Width of custom headers in ag-grid (angular) doesn't match with column's width
  • Issues with Katex/ngx-markdown Rendering in Angular 16
  • How to make Angular SSR wait for async operations to finish that are initiated in ngOnInit?
  • I want to install @angular/google-maps npm Package in angular 16.2.12 but "npm install @angular/google-maps" this is not working/ tell me other query
  • Angular 17 standalone application integrate CKEditor 5 -- Error: window is not defined
  • Why is $scope >= 0 showing true in interpolation while empty in controller?
  • The XMLHttpRequest compatibility library was not found
  • Making Gantt Chart Column Labels More Readable
  • Pass key-value pairs of object as individual arguments to component in Angular

Related Questions in BROWSER

  • (in promise) TypeError: NetworkError when attempting to fetch resource
  • How could i add a bookmark and tabs function in PySide6?
  • Difficulty Accessing HTTP URLs/IP Addresses Due to Browser Redirecting to HTTPS: Seeking Solutions
  • Can be their an extension to save pages in as offline in the browser itself?
  • Connecting puppeteer to an existing Brave Browser instance using
  • How can I modify javascript native fetch function from an extension?
  • Update your browser to use...in android webview application
  • Why does throwing an error in any browser developer console not get caught by window.addEventListener('error')?
  • The javascript and css files cached by chrome do not belong to the same version
  • Unlike chrome Unable to create multiple instance of sidepanel while creating extension for edge browser
  • Cannot import a class from a WebPacked javascript file
  • How do I keep the same time input style in both firefox and chrome
  • Use GUI application on Github Codespace
  • get cpu / gpu capabilities from client in react / typescript?
  • How to close a browser context after multiple test is written in same file

Related Questions in BROWSER-REFRESH

  • Angular 16 / Flask Browser Refresh - How to Redirect to 'root'
  • How redirect to a page after browser refresh?
  • Set interval gets clear on browser refresh in my react application
  • nmp install -g under Windows 10, not recognized as a command
  • In my react app, url updates but the page does not redirect until browser refresh
  • I am facing problem with the react browser router nesting?
  • How to reload the same page on browser refresh in angularjs
  • How to reset form from php controller
  • Website is not loading on server while refresh it from browser in angular 2
  • Problem when loading routes from DB dynamically in angular 2
  • Is it possible to ALWAYS keep the cursor active in the text editor while using Browser Refresh with Sublime Text 3?
  • PHP website file will not refresh with button, but will with ctrl+F5
  • How to reload browser from code in Odoo 10
  • Detect F5 browser refresh from angular-ui-router
  • morgan skip not working

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?

Popular Tags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs node.js arrays c asp.net json

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)
  • Privacy
  • Terms
  • Cookies
  • Homegardensmart
  • Math
  • Aftereffectstemplates