14

Following error shown up in my console whenever my page loads.

"Uncaught Error: Syntax error, unrecognized expression: #/about"

My code is as below:

                <li class="active">
                    <a href="/">Home</a>
                </li>
                <li class="">
                    <a href="#/about" title="About Us">About</a>
                </li>
                <li class="">
                    <a href="#/pricing">Pricing</a>
                </li>

It shows for all initial instance of . Initially, it shows for #/about as it is first, If I remove about us tab it will show up for pricing page link.

Its not bootstrap tab issue, This are simple navigation only

Routing Code in app.js:

$routeProvider.when('/', {
        templateUrl: 'partials/home.html'
    }).when('/account', {
        templateUrl: 'partials/account.html',
    }).when('/terms', {
        templateUrl: 'partials/terms.html'
    }).when('/about', {
        templateUrl: 'partials/about.html'
    }).otherwise({
        redirectTo: '/'
    });

I have debug its issue of bootstrap, bootstrap nav causing this issue: "nav navbar-nav" fixes for this is data-target="#" but wants proper work around for this

4
  • What is your JS code related to routes? Commented Jul 19, 2015 at 5:40
  • Use <a ng-href="/about" title="About Us">About</a> Commented Jul 19, 2015 at 5:50
  • Tried that too still same error Commented Jul 19, 2015 at 5:51
  • I have debug, it's because of bootstrap, bootstrap navbar="nav navbar-nav" Commented Jul 19, 2015 at 6:24

4 Answers 4

17

This is most probably a Bootstrap issue. Try using data-targetattribute on your links like this

<a href="#/about" data-target="#about" title="About Us">About</a>
Sign up to request clarification or add additional context in comments.

4 Comments

Its not about modal, or bootstrap component, its just a nav link
This fixes my issue by adding data-target="#"
It's ok for all routes except "/": a(href='#/', data-target='#'). My route config is the same: $routeProvider.when('/', {templateUrl: /views/home/home.html'}). What i'm doing wrong?
I just removed all data-toggle attributes and fixed.
8

Ok you gotta remove the slash, '/' with which your html becomes,

<a href="#about" title="About Us">About</a>

If you want to keep the slash, '/' you gotta use data-target attribute as,

<a href="#/about" title="About Us" data-target="#about">About</a>

More about it here

4 Comments

Are you referring to tabs? - Its not a bootstrap tab, its a normal link only
Did you give it a try? Have you placed <div ng-view=""></div>??
Sorry, where do u asked me to put ng-view, it's header and i have used ng-include
better to use ng-view when you are using routing. You would generally have it in your index.html where you would inject views, goes pretty well with routing to form SPAs. Anyways did you get it fixed?
5

This issue happens also on angular 2 projects. I just add data-target="#" to the anchor link. It solved my problem.

 <a data-target="#" [routerLink]="['/link']">my link</a>. 

2 Comments

am facing the same issue like what you had faced. could pls share sample implementation of your codes
when i try your solution. router link getting open in new tab instead of same page
1

This may be a very rare situation, but I've got same error because of some legacy code using Colorbox and location.hash.

jQuery(function() {jQuery('.content-row .csc-default a').tooltip({placement:'top'});
jQuery('a.gallery').colorbox({
    maxWidth:'95%',
    maxHeight:'95%',
    slideshow:true,
    current:' {current} / {total}',
    opacity:'0.80',
    transition:'none',
    speed:'550',
    slideshowSpeed:'5500',
    overlayClose:true,
    fixed:false,
    escKey:true,
    arrowKey:true,
    loop:true,
    title: function() { return $(this).data('original-title')},
    close:'<span class="glyphicon glyphicon-remove"></span>',
    previous:'<span class="glyphicon glyphicon-chevron-left"></span>',
    next:'<span class="glyphicon glyphicon-chevron-right"></span>',
    slideshowStart:'<span class="glyphicon glyphicon-play"></span>',
    slideshowStop:'<span class="glyphicon glyphicon-pause"></span>',
    rel: function() { return $(this).data('rel')}
});
if (location.hash) $(location.hash).collapse('show'); //when this line is commented, Angular Route works properly
});

Strange thing is that error was happening only when loading page with link to view like localhost/index.html#/main or simply reloading page with any view selected.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.