Angular 2 Router issue, seeing errors in Developer tools console in platform-browser.umd.js

66 views
Skip to first unread message

vijender reddy

unread,
Jun 29, 2016, 11:14:59 AM6/29/16
to AngularJS

I tried to build Sample application in Angular 2 and I am able to create routing and it just works fine but I see errors in developer tools console window. Here is the plunker I created :

http://plnkr.co/edit/jJeQsLBOVrCz8QkxNAEc?p=preview

Also, even if I ignore those errors since it is working. I am having issues when I reload the the browser url it give me 404 issue, I build app in Visual studio 2015 Asp.net 4.5.2. I cannot demonstrate the reload issue using plunker as it will reload whole code.

In Visual studio: http://localhost:14637/ loads the initial page :




after I click on the route in my demo crisis center it is redirecting to crisis center page, but the moment I click on browser reload I am losing my whole routing and I get 404 issue, note: by that time i clicked on crisis-center route so angular should know it route already and when I reload the page i think it should pick the url route  ?




It somehow not picking up the routing. Any help is appreciated. 


I tried to put empty routing, and it did fix the issue in plunker but when i try the same code in Visual studio 2015 project i still get the same error



Sander Elias

unread,
Jun 29, 2016, 11:38:34 AM6/29/16
to AngularJS
Hi Vijender,

You need to configure your server for html5 routing. If you reload the page, the server is responsible to serve the right page (usually the index.html)
Reload means that the browsers will start from nothing, and then tries loading your page. As your app is not loaded yet, the router in there can't help you. This is true for all front-end apps that use a router.

Regards
Sander

vijender reddy

unread,
Jun 29, 2016, 12:26:50 PM6/29/16
to AngularJS
@Sander Elias, Thank you very much. Also I am having issues with routing I see error 

image

I tried to put empty routes it does fixes in plunker like i demonstrated above but the error is not going away in Visual studio 2015 project. Please reply at your convenience.

Sander Elias

unread,
Jun 29, 2016, 1:16:13 PM6/29/16
to AngularJS
Did you put in in the <base href=".">? I read some people do use <base href="/"> instead. The reasoning behind it eludes me for the moment though ;)
Missing the base href is often a reason for problems.

Regards
Sander

vijender reddy

unread,
Jun 29, 2016, 2:41:50 PM6/29/16
to AngularJS
@sander Elias,
         I did put both <base href="."> and also <base href="/"> both did not fix my above issue of cannot match any routes ''

HisDivineShadow

unread,
Jun 29, 2016, 3:29:33 PM6/29/16
to AngularJS
In your ASP.NET RouteConfig do you have an entry like this to redirect all routes to the index view on the home controller?

routes.MapRoute(
    name: "Default",
    url: "{*url}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
Reply all
Reply to author
Forward
0 new messages