Version: 2.1.2 (latest)

Page 404

You are reading the documentation for version 2 of FoalTS. Instructions for upgrading to this version are available here. The old documentation can be found here.

Here's a way to implement custom 404 pages.

import { Get, HttpResponseNotFound, HttpResponseOK } from '@foal/core';
class ViewController {
@Get('/home')
home() {
return new HttpResponseOK('You are on the home page!');
}
}
class AppController {
subControllers = [ ViewController ];
@Get('*')
notFound() {
return new HttpResponseNotFound('The page you are looking for does not exist.');
}
}

In case you want to intercept all HTTP verbs (POST, PUT, etc), you can also use the @All decorator for this.

import { All, HttpResponseNotFound } from '@foal/core';
class AppController {
subControllers = [ ViewController ];
@All('*')
notFound() {
return new HttpResponseNotFound('The route you are looking for does not exist.');
}
}