Angular 5 redirectionNMnithi mano8yAsked May 2, 2018, 8:40 PM EDTSolvedShareLinkedInXCopy linkSavewindow.location.href='../app/route/route.component.html'; I have given the above code. It is not working. KIndly provide me an alternate solution
Angular 5 redirectionNMnithi mano8yAsked May 2, 2018, 8:40 PM EDTSolvedShareLinkedInXCopy linkSavewindow.location.href='../app/route/route.component.html'; I have given the above code. It is not working. KIndly provide me an alternate solution
Dharmraj ThakurRank #577 · 4.2K reputation8y agoPosted May 3, 2018, 6:41 AM EDT✓ Accepted answer+1I means saw your route.component.ts or try window.location.href='/';+1
Dharmraj ThakurRank #577 · 4.2K reputation8y agoPosted May 3, 2018, 12:02 AM EDT+2Redirection using javascript while working on angular is bad practise. In HTML:<a routerLink="/Home/Index"><button class="btn btn-success pull-right" > Homebutton>a> Typescript: import { Router } from '@angular/router'; //...... constructor(private router: Router) { } //...... public btnClick() { this.router.navigateByUrl('/home/Index'); }; //...... Still, you want to redirect using javascript then try by giving route path not file path... window.location.href='/Home/Index';+2Raghavendar SwaminathanRank #788 · 2.9K reputation8y agoPosted May 2, 2018, 8:47 PM EDT+1Hi Nithi, var current_url= $window.location.host; var redirect_url = "the url you want to redirect"; $window.location.href = redirect_url; Hope it would works. Links:http://findnerd.com/list/view/Redirect-to-a-new-pageurl-in-AngularJS/17444/ https://angular-2-training-book.rangle.io/handout/routing/redirects.html +1NMnithi manoRank #8,652 · 218 reputation8y agoPosted May 3, 2018, 12:14 AM EDT+1Yes I want to redirect using javascript then try by giving route path not file path. My folder structure is -> angular5(Project name) -> route.component.html(Component name). Pls let me know how to provide redirection uing javascript " window.location.href " in angular 5+1MAMohan ArumugamRank #5,109 · 311 reputation8y agoPosted May 3, 2018, 1:35 AM EDT+1when the app is (re)initialized, you are being redirected to root page. export class AppComponent { Constructor(Private router: router) { } ngOnInit () { this.router.navigate( [' '] ) } } +1Mahesh VermaRank #475 · 5.2K reputation8y agoPosted May 2, 2018, 8:50 PM EDT0Hi Nitin,"route.component.html" file is present on the same project or you redirect from it another page?0NMnithi manoRank #8,652 · 218 reputation8y agoPosted May 2, 2018, 10:26 PM EDT0It is present in the same project.0Dharmraj ThakurRank #577 · 4.2K reputation8y agoPosted May 3, 2018, 12:54 AM EDT0Can you show your route.component.html or can you tell me the URL of your page.0NMnithi manoRank #8,652 · 218 reputation8y agoPosted May 3, 2018, 3:28 AM EDT0Hi DHarmraj, route.component.html just has a Hello 0NMnithi manoRank #8,652 · 218 reputation8y agoPosted May 3, 2018, 8:05 AM EDT0Hi Dharmraj, Can you pls give the complete syntax for window.location.href='/'; I mean from which folder name i need to mention in window.location.href ?? 0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Raghavendar SwaminathanRank #788 · 2.9K reputation8y agoPosted May 2, 2018, 8:47 PM EDT+1Hi Nithi, var current_url= $window.location.host; var redirect_url = "the url you want to redirect"; $window.location.href = redirect_url; Hope it would works. Links:http://findnerd.com/list/view/Redirect-to-a-new-pageurl-in-AngularJS/17444/ https://angular-2-training-book.rangle.io/handout/routing/redirects.html +1
NMnithi manoRank #8,652 · 218 reputation8y agoPosted May 3, 2018, 12:14 AM EDT+1Yes I want to redirect using javascript then try by giving route path not file path. My folder structure is -> angular5(Project name) -> route.component.html(Component name). Pls let me know how to provide redirection uing javascript " window.location.href " in angular 5+1
MAMohan ArumugamRank #5,109 · 311 reputation8y agoPosted May 3, 2018, 1:35 AM EDT+1when the app is (re)initialized, you are being redirected to root page. export class AppComponent { Constructor(Private router: router) { } ngOnInit () { this.router.navigate( [' '] ) } } +1
Mahesh VermaRank #475 · 5.2K reputation8y agoPosted May 2, 2018, 8:50 PM EDT0Hi Nitin,"route.component.html" file is present on the same project or you redirect from it another page?0
NMnithi manoRank #8,652 · 218 reputation8y agoPosted May 2, 2018, 10:26 PM EDT0It is present in the same project.0
Dharmraj ThakurRank #577 · 4.2K reputation8y agoPosted May 3, 2018, 12:54 AM EDT0Can you show your route.component.html or can you tell me the URL of your page.0
NMnithi manoRank #8,652 · 218 reputation8y agoPosted May 3, 2018, 3:28 AM EDT0Hi DHarmraj, route.component.html just has a Hello 0
NMnithi manoRank #8,652 · 218 reputation8y agoPosted May 3, 2018, 8:05 AM EDT0Hi Dharmraj, Can you pls give the complete syntax for window.location.href='/'; I mean from which folder name i need to mention in window.location.href ?? 0
Dharmraj ThakurRank #577 · 4.2K reputationPosted May 3, 2018, 6:41 AM EDT
Dharmraj ThakurRank #577 · 4.2K reputationPosted May 3, 2018, 12:02 AM EDT
Raghavendar SwaminathanRank #788 · 2.9K reputationPosted May 2, 2018, 8:47 PM EDT
nithi manoRank #8,652 · 218 reputationPosted May 3, 2018, 12:14 AM EDT
Mohan ArumugamRank #5,109 · 311 reputationPosted May 3, 2018, 1:35 AM EDT
Mahesh VermaRank #475 · 5.2K reputationPosted May 2, 2018, 8:50 PM EDT
"route.component.html" file is present on the same project or you redirect from it another page?
nithi manoRank #8,652 · 218 reputationPosted May 2, 2018, 10:26 PM EDT
Dharmraj ThakurRank #577 · 4.2K reputationPosted May 3, 2018, 12:54 AM EDT
nithi manoRank #8,652 · 218 reputationPosted May 3, 2018, 3:28 AM EDT
Hello
nithi manoRank #8,652 · 218 reputationPosted May 3, 2018, 8:05 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts