ui-router icon indicating copy to clipboard operation
ui-router copied to clipboard

Syntax error, unrecognized expression: #/...

Open edamron opened this issue 12 years ago • 18 comments

I recently started getting these errors when I click on a ui-sref link, EVEN THOUGH it still takes me to the given state / templateUrl. Here's a small snippet from my app.js file:

        .state('prepare', {
            abtract: true,
            url: '/prepare',
            templateUrl: 'prepare/prepare.html',
            controller: 'prepareController'
        })
            .state('prepare.propinss', {
                url: '/propinss',
                templateUrl: 'prepare/question.html'
            })

The abstract state ('prepare') doesn't cause an error to be recorded in the log, but the 'prepare.propinss' state does cause it:

Uncaught Error: Syntax error, unrecognized expression: #/prepare/propinss

BTW, the actual error itself comes from jquery.js:1437 (Sizzle.error = func...).

It seems I can safely ignore this error, but I'd prefer to eliminate it, just in case it does eventually cause me a real issue.

Thanks!

edamron avatar Oct 03 '14 17:10 edamron

I had a very similar issue, and traced it to the function StateRefActiveDirective

In my case, it is being caused by this line in the function $scope.$on('$stateChangeSuccess', update);

When the event occurs and update is called, the variable state is null, since this.$$setStateInfo has not been called, so in the update function when isMatch is executed, the following line return $state.includes(state.name) && matchesParams();

causes an exception "Cannot read property 'name' of null"

I reverted back to version 0.2.10 from 0.2.11 and I do not get the exception.

Thanks Rick

function $StateRefActiveDirective($state, $stateParams, $interpolate) {
  return  {
    restrict: "A",
    controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
      var state, params, activeClass;

      // There probably isn't much point in $observing this
      // uiSrefActive and uiSrefActiveEq share the same directive object with some
      // slight difference in logic routing
      activeClass = $interpolate($attrs.uiSrefActiveEq || $attrs.uiSrefActive || '', false)($scope);

      // Allow uiSref to communicate with uiSrefActive[Equals]
      this.$$setStateInfo = function (newState, newParams) {
        state = $state.get(newState, stateContext($element));
        params = newParams;
        update();
      };

      $scope.$on('$stateChangeSuccess', update);

      // Update route state
      function update() {
        if (isMatch()) {
          $element.addClass(activeClass);
        } else {
          $element.removeClass(activeClass);
        }
      }

      function isMatch() {
        if (typeof $attrs.uiSrefActiveEq !== 'undefined') {
          return $state.$current.self === state && matchesParams();
        } else {
         return $state.includes(state.name) && matchesParams();
        }
      }

      function matchesParams() {
        return !params || equalForKeys(params, $stateParams);
      }
    }]
  };
}

rickj33 avatar Oct 06 '14 18:10 rickj33

+1

I have the same issue with 'ui-sref'

seinavco avatar Oct 29 '14 14:10 seinavco

+1

kolesnik avatar Nov 15 '14 21:11 kolesnik

Any solution on this issue? I'm facing the same . I'm using @version v0.2.13

rahil471 avatar Dec 30 '14 09:12 rahil471

i too had the same issue and after few hours stuggle, i found out i had something like this in the navigation bar. i just removed data-toggle="collapse" and problem solved.

Removing uses of data-toggle with ui-sref solved the issue for me

stwiname avatar Jan 15 '15 19:01 stwiname

@stwiname thnx worked beautifully. so fixed by removing data-toggle="tab"

sulmanen avatar Feb 16 '15 14:02 sulmanen

+1 Having this issue with v0.2.13

@stwiname's fix works, but I don't want to remove the data-toggle="collapse" because I need it.

renesansz avatar Feb 19 '15 14:02 renesansz

@stwiname, working

rajesh38 avatar May 07 '15 07:05 rajesh38

worked for me as well thanks

gauravkhullar1690 avatar May 13 '15 10:05 gauravkhullar1690

I am on v0.2.11 and I was seeing the same error with a ui-sref tag that was used along with data-toggle="tab", though not sure why the data-toggle was added in the first place. Removing it as pointed out in this post helped fix the problem.

VegaFromLyra avatar Jul 17 '15 16:07 VegaFromLyra

https://gist.github.com/eddiemonge/f6a58169c2846731a1eb

eddiemonge avatar Aug 18 '15 21:08 eddiemonge

Had the same problem. Check here - http://stackoverflow.com/questions/16785264/jquery-syntax-error. No need to delete the data-toggle. The problem is in '/' in hrefs (I had nested states and url for parent state, so I had url "#/parent_state_url/child_state_url" and I was getting the issue because of "/". I deleted url for parent state and it works.). Hope this helped.

SeregaSh avatar Oct 06 '15 17:10 SeregaSh

I also faced the same issue with ui-sref, removing data-toggle attribute solved it. @skannan74 Thanks for the fix!

jitendersandhu avatar Jan 13 '16 19:01 jitendersandhu

@skannan74 thank it works

shreyasBhargava avatar Apr 23 '16 06:04 shreyasBhargava

If you use bootstrap, remove the "nav" class:

s1lviu avatar Dec 04 '16 15:12 s1lviu

@skannan74 thanks its working for me.

muratgucuk avatar Dec 27 '17 19:12 muratgucuk

Is there an actual fix to this? I hardly see how stripping out functionality is an appropriate resolution to this.

ghost avatar Jan 04 '19 03:01 ghost