Do you know you can earn heaps of $$ by answering questions on kodlogs, for more info contact us through feedback link at footer? We are Australian based web site and pay you for answering questions

  • Register
Welcome to Kodlogs Q&A, where you can ask programming questions and receive answers from other members of the community. For programmers, by programmers Kodlogs is an open community for anyone that does coding. We help you get answers to your toughest coding questions, share knowledge with your coworkers in private, and find your next IT dream job.
0 votes

I am using Angular 2.0.0-alpha.30 version. When redirect to a different route, then refresh the browser , its showing Cannot GET /route.

Can you help me with figuring why this error happened.

by (8.8k points)  
reshown by

1 Answer

0 votes
Best answer

The error you are seeing is because you are requesting http://localhost/route which doesn't exist. According to Simon.

When using html5 routing you need to map all routes in your app(currently 404) to index.html in your server side. Here are some options for you:

  1. using live-server:

    $live-server --entry-file=index.html

  2. using nginx:

    error_page 404 /index.html

  3. Tomcat - configuration of web.xml. From Kunin's comment

    <error-page> <error-code>404</error-code> <location>/index.html</location> </error-page>

Disclaimer: this fix works with Alpha44

I had the same issue and solved it by implementing the HashLocationStrategy listed in the API Preview.

Start by importing the necessary directives

import {provide} from 'angular2/angular2';
import {
} from 'angular2/router';

And finally, bootstrap it all together like so

bootstrap(AppCmp, [
  provide(LocationStrategy, {useClass: HashLocationStrategy}) 


by (8.8k points)