Kirk Strobeck
Kirk Strobeck

Reputation: 18589

`SyntaxError: Unexpected token <`

Getting this error

SyntaxError: Unexpected token <

Whenever we add

$locationProvider.html5Mode(true);

For some reason it seems to start parsing resources as JS.

See

// App configuration
app.config(['$routeProvider', '$locationProvider',
  function($routeProvider, $locationProvider) {

    $routeProvider.when('/', {
        templateUrl: 'partials/home.html'
    });

    $locationProvider.html5Mode(true);
  }]
);

Upvotes: 0

Views: 1006

Answers (2)

Ronald Reis
Ronald Reis

Reputation: 11

I had this problem once. The cause was a missing slash ("/") in the begning of the source paths (src) of scripts files. In your index.html, the script resources must be similar to this (note the beginning slash in each path):

<script type="text/javascript" src="/js/angular.js"></script>
<script type="text/javascript" src="/js/angular-route.js"></script>
<script type="text/javascript" src="/js/app.js"></script>

In index file, its also necessary put this in the head section:

<base href="/" />

In the app.config section, each templateUrl must start with a slash ("/")

If you are testing in localhost (I use XAMPP for my tests), its required creating a virtual host too.

Upvotes: 1

Jayram
Jayram

Reputation: 19578

The fix I would suggest you to check your server side code where you need to add all your static files are declared before any other routes.

Also make sure the path you have added for the static files are the correct ones.

Upvotes: 1

Related Questions