Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller runs twice when activating a state with slash in the params #2339

Closed
cvn opened this issue Oct 27, 2015 · 10 comments
Closed

Controller runs twice when activating a state with slash in the params #2339

cvn opened this issue Oct 27, 2015 · 10 comments
Labels
Milestone

Comments

@cvn
Copy link
Contributor

cvn commented Oct 27, 2015

When activating a state with a slash in the params, it will call that state's controller twice.

$state.go('myState',{previous:'/last/page'});

I wrote some tests to demonstrate:

http://plnkr.co/edit/WgBVFpArGhamZe5mVtWz?p=preview

Thanks to @kathygit for discovering this, as well as providing a workaround (url encoding the slashes) in the issue referenced below.

Tested with Angular 1.4.7 and UI-Router 0.2.15.

@uaoleg
Copy link

uaoleg commented Nov 10, 2015

@cbfranca
Copy link

+1 I have the same issue

@anymos
Copy link

anymos commented Nov 14, 2015

It s not like nobody is using a parameter as return path with / inside ...

How it s possible to have this bug if there is testing ?

@manishsingh2508
Copy link

Hello,

I am facing the similar issue. the controller is called twice which is causing a major problems.
I am using the 0.2.15 version.

I am surprised the issue still exists . Can anyone help me how can i resolve the issue. The parameter passed here is mandatory and it can be Y or N.

See the example.
Template
ui-sref=".newProject({fromTempl:fromTemplate})

Configuration
.state('home.projTypeView',{
url: '/projTypeView/:fromTempl',
views: {
'mainContainerView@': {
templateUrl: 'apps/views/projectTypeList.html',
controller:'projectTypeListController',

      }
 }

})
Please help me out . I could not find any answer .
Regards,
Manish Singh

@cbfranca
Copy link

+1

@mrfatgoat
Copy link

+1
Exactly the same issue here

I should note that the second time the controller runs, the parameter IS indeed properly URL encoded, as opposed to the first time where it is not.

@PierrickMartos
Copy link

Same here.

@christopherthielen christopherthielen added this to the 0.2.16 milestone Jan 23, 2016
@christopherthielen
Copy link
Contributor

http://plnkr.co/edit/7sJQL9UEMlwiwYSqglvX?p=preview

@linker-err0r
Copy link

linker-err0r commented Oct 6, 2016

This is happening again as of 0.3.1.

Caller:

      $state.go('eggly.categories.bookmarks', {
        category: category.name
      });

State Module:

angular
  .module('categories.bookmarks', [
    'categories.bookmarks.create',
    'categories.bookmarks.edit',
    'eggly.models.categories',
    'eggly.models.bookmarks',
])
.config(function ($stateProvider) {
  $stateProvider
    .state('eggly.categories.bookmarks', {
      url: 'categories/:category',
      views: {
        'bookmarks@': {
          templateUrl: 'app/categories/bookmarks/bookmarks.template.html',
          controller: 'BookmarksCtrl'
        }
      }
    })
})
.controller('BookmarksCtrl', function ($scope, $stateParams) {
  // This gets called twice, once with `$stateParams.category` filled, and next time it's `undefined`
  $scope.currentCategoryName = $stateParams.category;
});

Additionally, the route in the address bar is reset to default / as well...

As noted above, the same workaround from before still works, that is, replacing / with %2F produces the proper result.

@christopherthielen
Copy link
Contributor

@DeathGaze can you put this in a plunker ? http://bit.ly/UIR-Plunk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants