Inside an Angular project I have a function. When I run it, I expect to go to the home.
Inside my function I have a condition, if is true I want to redirect.
if (condition) {
location.url('/home');
// code...
}
Slightly confused what you mean by "redirect". If you have a condition that determines the final location, then you can just use go to one or the other.
if(location) {
$location.url('/home');
} else {
$location.url('/otherDestination');
}
If you mean a true redirect that reflects in the window history, read about the $location.replace function provided by AngularJS. Scroll down to the section labeled 'Replace method'. Hope this helps!
$location.url('/otherDestination').replace();
if (task.id == id ) { location.url('/home'); // code... }
location.href = ...you are using the native js redirect, which forces your app to refresh. (which hurts user experience)