Angular ui router - Transitioning from one state to the same state, when no parameters are provided, results in

Check out the Plunker Demo

  <script>
    var myapp = angular.module('myapp', ["ui.router"])
     myapp.config(function($stateProvider, $urlRouterProvider) {

      // If there is no matching URL, go to /dashboard
      $urlRouterProvider.otherwise("/dashboard")

      $stateProvider
        .state('dashboard', {
          url: '/dashboard',
          templateUrl: 'dashboard.html',
          controller: 'MainCtrl'

        })
        .state('verify', {
          url: '/verify?email&code',
          templateUrl: 'verify.html',
          controller: 'verifyCtrl'
        })
    });
    myapp.controller('MainCtrl', function($scope,$state) {
      $scope.goTo = function () {
        $state.go('verify',{'email':'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90e0f1e2f1fdd0e4f5e3e4bef3fffd">[email protected]</a>', 'code': {'name': 'test name'}});
      }
    })
    myapp.controller('verifyCtrl', function($scope, $stateParams) {
      $scope.email = $stateParams.email;
      $scope.code = $stateParams.code.name;
    })
  </script>

If you navigate from a state with parameters to the same state without parameters, it won't work.

In the demo, click on "verify with email & code" first and then click on the other link "verify without params". You'll notice that it doesn't navigate correctly.

Answer №1

When transitioning from one state to another, the State properties are commonly inherited. This means that the parameters are also copied over unless they are explicitly defined. To prevent this inheritance, you can use the option inherit=false.

If you are using the ui-serf library, you can utilize the ui-sref-opts attribute to enable this option.

Check out this Demo-Plunker

In HTML:

<a ui-sref="verify" ui-sref-opts="{inherit: false}">Click here to verify without any parameters</a>

In JavaScript:

$state.go('verify', {}, {inherit:false});

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

Adjustable div height: reduce until reaching a certain point and then begin expanding once more

Incorporating a hero section to display content is my current approach. The design adapts responsively utilizing the padding-bottom percentage strategy, along with an inner container that is absolutely positioned for central alignment of the content. The ...

Can we utilize object properties in this manner?

Hey there! I've been experimenting with the react-bootstrap library recently, trying to get better at using it. While going through the tutorial, I came across some ES6 code that caught my attention. function FieldGroup({ id, label, help, ...props } ...

Is your Jquery validation malfunctioning?

I am currently facing a challenge with required validation on an asp.net page. In order to validate the inputs, I have implemented multiple controls which can be hidden or displayed based on certain conditions. These controls include checkboxlists, dropdow ...

Method for transmitting JSON array from Controller to View using CodeIgniter

I have a function in my controller: function retrieveAllExpenses() { $date=$this->frenchToEnglish_date($this->input->post('date')); $id_user=$this->session->userdata('id_user'); $where=array('date&ap ...

The initial return value of $(document).height may be inaccurate, but is accurate upon recalculation

I am working on implementing a pop-up screen and I would like to darken the background when it opens. Below is the Javascript code: $(document).on('click', '.item', function(){ $("#popUp").css("display" , "block"); ...

When working with Function components in NextJS, it's important to note that they cannot be assigned refs directly. If you're trying to access a ref within a Function component, you

I'm having an issue with wrapping a card component using the Link component from 'next/link'. Instead of redirecting me to the desired link when I click the card, I receive a warning that says 'Function components cannot be given refs. ...

How can I achieve a similar functionality to array_unique() using jQuery?

When I select values from a dropdown, they are stored as an array like ["1","2","3"] Upon each change, the code below is executed to generate a new array based on the selected values: $('#event-courses-type').on('change', function(){ ...

Sharing the checkbox's checked status with an AJAX script

I am faced with a challenge involving a table that contains checkboxes in the first column. When a checkbox is checked, it triggers an AJAX script that updates a PHP session variable with the selected values. The functionality is currently operational, but ...

Preventing default behavior in a JQuery post request

Encountering an issue with jQuery functionality on a mobile device. function send() { $.post("scripts/post.php", { username: $("input[name=username]").val(), password: $("input[name=password]").val() }, function(data) { if ($(".data div" ...

What is the best way to display AdSense ads exclusively on webpages with a height exceeding 2400 pixels?

Looking to gather data on page height in order to display adsense only on pages with over 2400px height. Any suggestions would be greatly appreciated! <script> var height = $(document).height(); if (document > 2400 ) { echo '<!--adsense ...

What is the definition of the term "WebapiError"?

I'm currently developing a Spotify Web App that focuses on retrieving the top albums of KD Rusha using the Client ID and Artist ID to exclusively fetch his releases on Spotify. To accomplish this, I am utilizing an npm package called spotify-web-api-n ...

The button in my form, created using React, continuously causes the page to refresh

I tried to create a chat application using node.js and react.js. However, I'm facing an issue where clicking the button on my page refreshes the entire page. As a beginner in web development, please forgive me if this is an obvious problem. You can fi ...

Tips for interpreting JSON information and showcasing it with the assistance of Ajax in JQuery?

There's a request made to the system via AJAX that returns JSON as a response, which is then displayed in an HTML table. The HTML code for displaying the data looks like this: <table id="documentDisplay"> <thead> <tr ...

There is a lack of 'Access-Control-Allow-Origin' header - Issue encountered while making Food2Fork API request using AJAX

Our team has just embarked on our first project, and I've encountered a roadblock while conducting API testing. Specifically, I am struggling to generate a successful access control header. Is there anyone who can provide assistance in troubleshooting ...

There are times when window.onload doesn't do the trick, but using alert() can make

I recently posted a question related to this, so I apologize for reaching out again. I am struggling to grasp this concept as I am still in the process of learning JavaScript/HTML. Currently, I am loading an SVG into my HTML using SVGInject and implementi ...

TextGeometry failing to render

Currently experimenting with TextGeometry. Successfully implemented BoxGeometry, but encountering issues with TextGeometry. Experimenting with different material options like MeshNormalMeterial, however, still unable to resolve the issue var scene = new ...

Exploring Unanchored Substring Queries in Loopback API

Searching for a solution to implement a basic substring query using the loopback API for a typeahead field. Despite my efforts, I have not been able to find a clear answer. I simply want to input a substring and retrieve all brands that contain that subst ...

Unleashing the potential of Chrome's desktop notifications

After spending the past hour, I finally found out why I am unable to make a call without a click event: window.webkitNotifications.requestPermission(); I am aware that it works with a click event, but is there any way to trigger a Chrome desktop notifica ...

Heroku deployment causes Node.js application to crash

My Node.js app works perfectly fine locally, but once deployed on Heroku, it fails to run. I have already deployed it from my Github repository. If anyone could try deploying the app from my repo and identify the cause of the issue, that would be greatly ...