.Net Interview Questions and Answers

Search:

Angular 2 tips and tricks:- HashLocation strategy ( Handling Refresh)

By : Shiv Prasad Koirala | May 4th, 2017 | Views : 169 | Comments : 0 Bookmark and Share

Everyone loves hitting refresh ( f5) button if things are not working while surfing. In angular 2 applications when you hit refresh it hits the server and you end up with such exceptions. The exception is right because the hit has gone to MVC controller and controller does not have anything for defined as such.



So in order to handle the same we need to do use "HashLocationStratergy". So in your main module you need to define the strategy in the providers.


....
import HashLocationStrategy,LocationStrategy } from "@angular/common";
@NgModule(
.....
....    
providers: [        
 provide: LocationStrategy, useClass: HashLocationStrategy }    
]
})


Once you do that and when you start browsing the angular 2 application . you will see "#" sign as shown in the below figure which indicates that hash location strategy is in action.



"#" in a URL means that do not hit the server try to hit local HTML page. So now if you try refresh you will see that page refreshes but it does not hit MVC controller and does not show the not found page error.


I have also included this topic in my Angular 2 training Mumbaisyllabus as I feel it's a very important feature.


Below is step by step video from Angular 2 project series which is fully practical& easy to understand:


 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
1 1 1 2 1
 
Article Tags : Angular 2 , Tips Tricks , HashLocation ,
 
 
 

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

Article Categories

Learn in Hindi