The Startup
Published in

The Startup

Use Your 404 Pages to Be as Influential as Amazon in Ionic 5

Everyone has done it before. You type in a website then stop and stare at the 404 page that is on the screen. You ask yourself, “Did I not type it in right? Did the website delete?”

What if everyone who visited that 404 page was met with the pictures of animals up for adoption? That was my thought when I visited an Amazon 404 Error page and saw “Dogs of Amazon.” If you haven’t seen this page, click here.

An increasingly popular way for animals to get adopted is on social media, where they do a funny trick or we get to watch their months-long transformation video in under 3 minutes. By transforming the 404 page, we can help change the lives of hundreds of animals across the world.”

Getting Started

To be able to achieve such a goal, we need to have a database somewhere that has a collection of adoptable dogs as well as an API to communicate with it. For this, we are using PetFinder. PetFinder is an online list of adoptable dogs and cats that has everything we are looking for.

For this example, I will be creating an Ionic App that when the user tries to visit a page that isn’t there, it’ll redirect them to the new 404 page. If you would like to go a different route, click here to go to the PetFinder API documentation and find out more ways to integrate this into your application! If you would like to use the same type of app I will be using, then follow the steps below:

Step 1: Starting Out

Like all projects, the first thing we must do is to initialize Ionic by:

ionic start IonicAnimalErrorApp blank

This will create a project that we can then cd IonicAnimalErrorApp into. If it asks for you to select a language, select Angular, and if it asks if you would like to integrate Capacitor then select yes.

Step 2: Creating the 404 Page

When we have stepped into the project, we now need to create a page that will host the 404 Error Page:

ionic g page error-page

Step 3: Adding The Routing

When we generate the Error Page it added a route to visit the Error Page, but it didn’t solve all the routing issues pertaining to users going to pages that are not actually there. To solve that issue, we simply add the following bolded line of code to the end of the Routes variable in `app-routing.module.ts`.

const routes: Routes = [
path: 'home',
loadChildren: () => import('./home/home.module').then( m => m.HomePageModule)
path: '',
redirectTo: 'home',
pathMatch: 'full'
path: '404',
loadChildren: () => import('./error-page/error-page.module').then( m => m.ErrorPagePageModule)
{path: '**', redirectTo: '/404'},

Step 4: Adding The Error Page Code

Before we start working on the actual Error Page, we need an API Key. To get this, please click here to visit PetFinder to retrieve an API key. Once we have an API and Secret Key, we can then run the following:

npm install --save @petfinder/petfinder-js

This will install all the packages that we need to communicate with the PetFinder API.

Now to make this easier to understand, let’s add an interface by running:

ng g interface interfaces/animal.ts

Below, I list out each page and what needs to be added to the pages to build this application.


export interface AnimalInterface {
name: string;
type: string;
url: string;
status: string;
description?: string;
image?: string;

import { Component, OnInit } from '@angular/core';
import { Client } from "@petfinder/petfinder-js";
import { AnimalInterface } from "../interfaces/animal";

selector: 'app-error-page',
templateUrl: './',
styleUrls: ['./'],
export class ErrorPagePage implements OnInit {
client = new Client({

public animalInfo: AnimalInterface;
public datalist;

constructor() { }

ngOnInit() {
.then( (response) => {
this.datalist =[0];
this.animalInfo = {
type: this.datalist.type,
image:[0].medium || "",
url: this.datalist.url,
status: this.datalist.status,
description: this.datalist.description
.catch(function (error) {
// Handle the error
console.log("Error: ", error);



<ion-content *ngIf="datalist">
<div id="container">
<h1>404 Error</h1>
<p>We may not have found that page you were looking for, but we found this {{ animalInfo.type }} that needs a loving family!</p>
<img src="{{ animalInfo.image }}" *ngIf="!!animalInfo.image" alt="Animal Image" id="animalImg"> <h3><a href="{{ animalInfo.url }}" title="View More Information!">{{ }}</a></h3>
<p>{{ animalInfo.description }}</p>
<p>Status: {{ animalInfo.status }}</p>

#container {
padding: 15px;
text-align: center;

#animalImg {
width: 80%;
display: inline-block;

Step 5: Running It

Now that we have added the code for it to run properly, the only thing left to do is run it and test it out. To run it, we simply type ionic serve in the terminal and hit enter. When the app finally loads, go to the URL and try to traverse to a route that you know isn’t there. In my case, I would traverse to http://localhost:8100/ThisIsNotARealRoute .


If you would like a copy of everything I went over in this article, click here and you will be able to view the repository.

If you would like to view my previously written articles or connect with me, visit my website by clicking here!




Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +756K followers.

Recommended from Medium

Installing Selenium Webdriver on Your Mac

[Quick Tutorial] Scrape & Index All Your Backlinks (Free)

5 Easy steps to deploy a React App in Github Pages

JavaScript for Web Application Development

My goals for Zuri Internship

JavaScript: Object.defineProperty

React clean code, coding style guide, and best practice

jQuery Click Outside DIV

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thomas George

Thomas George

💻 1st Phorm #Ionic Mobile Applications #Developer ☕️ Espresso Fanatic 🇺🇸 Chauvinist

More from Medium

White Space Alignment Insanity

Tech Interviews are broken

Do you know how to test for click events on icons? (#19)