0

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);
  }]
);
3
  • You are sure partials/home.html exists? Commented Jan 16, 2014 at 15:20
  • Your server should serve static assets: stackoverflow.com/questions/21067717/… Commented Jan 16, 2014 at 15:42
  • Yes, the error goes away when we comment out the html5Mode line and the app works perfectly, but with hashbangs. Commented Jan 16, 2014 at 16:16

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

We're setting app.use(express.static(assets)); first in the express server
1

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.

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.