-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add "no server side rendering" guard to protect routes that sho…
…uld not be rendered in SSR (#1277) * used for all checkout pages that should only be rendered in the users browser
- Loading branch information
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { CanActivate, Router } from '@angular/router'; | ||
|
||
/** | ||
* guards a route against server side rendering (e.g. if the logic requires information only available in browser rendering) | ||
*/ | ||
@Injectable({ providedIn: 'root' }) | ||
export class NoServerSideRenderingGuard implements CanActivate { | ||
constructor(private router: Router) {} | ||
|
||
canActivate() { | ||
// prevent any handling in the server side rendering (SSR) and instead show loading | ||
if (SSR) { | ||
return this.router.parseUrl('/loading'); | ||
} | ||
|
||
// if not in SSR just return true and continue | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters