Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better way to redirect #54

Open
mrpotato3 opened this issue Feb 12, 2016 · 1 comment
Open

Better way to redirect #54

mrpotato3 opened this issue Feb 12, 2016 · 1 comment

Comments

@mrpotato3
Copy link

Hi!

after many test I think this is the best way to redirect in LoggedInOutlet.ts.

activate(ci:ComponentInstruction)
{
  let url = this.parentRouter.lastNavigationAttempt;
  let route;

  if (!this.publicRoutes[url] && !localStorage.getItem('jwt'))  // !isAuth + !publicRoute -> Redirect to login
    route = ['Login'];
  else if (this.publicRoutes[url] && localStorage.getItem('jwt'))  // isAuth + publicRoute -> Redirect to dashboard
    route = ['Main'];
  else  // Continue routing without changes
  {
    this.parentRouter.navigateByUrl(url);
    return super.activate(ci);
  }

  this.parentRouter.navigate(route);
  return super.activate(this.parentRouter.generate(route).component);
}

This avoids to show other parts of the web.

I hope this helps.

@dmastag
Copy link

dmastag commented Jun 23, 2016

This is a great suggestion, but at my attempt the url have now an additional "/" in front of them so I had to add that to the publicRoutes. But this fixed a Bug that I had on my instance.

Thanks @mrpotato3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants