September 2017
Intermediate to advanced
450 pages
11h 24m
English
Let's add a 404 page to our application for when a user attempts to access an invalid route:
...export class PostComponent implements OnInit { postId = null; constructor(private route:ActivatedRoute, private router:Router) { route.params.subscribe( params =>{ this.postId = parseInt(params['id']); if (isNaN(this.postId)) { this.router.navigateByUrl("/404") } } ); }}
...if (isNaN(this.postId)) { this.router.navigateByUrl("/404", { skipLocationChange: true })}...
Read now
Unlock full access