Currently, I have been dedicating my time to developing a single page application using Vue 3, TypeScript, and integrating The Movie Database (TMDB) API.
My current focus is on creating a custom 404 error page for the application.
In the file src\router\index.ts
, you will find the following code:
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import HomeView from '../views/HomeView.vue';
import TopRatedMoviesView from '../views/TopRatedMoviesView.vue';
import MovieDetailsView from '../views/MovieDetailsView.vue';
import ActorDetailsView from '../views/ActorDetailsView.vue';
import NotFoundView from '../views/NotFoundView.vue';
const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'home',
component: HomeView
},
{
path: '/top-rated',
name: 'top_rated',
component: TopRatedMoviesView
},
{
path: '/movie/:id',
name: 'movie_details',
component: MovieDetailsView
},
{
path: '/actor/:id',
name: 'actor_details',
component: ActorDetailsView
},
{
path: '/:pathMatch(.*)*',
name: "404",
component: NotFoundView
},
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
export default router
Within the file src\views\NotFoundView.vue
, this is the content:
<template>
<div class="container d-flex">
<div class="text-center">
<h1 class="mb-3">404 | page not found</h1>
<router-link class="btn btn-sm btn-success" to="/">
<strong>Go to the Homepage</strong>
</router-link>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'NotFoundView',
});
</script>
The expected behavior is that the 404 view should display when there is a random string after the root URL, like
http://localhost:8080/someNonExistingPath
.
However, an issue arises when providing an incorrect parameter to a dynamic route, as seen in
http://localhost:8080/movie/a615656
.
I am seeking guidance on troubleshooting this issue and implementing a more reliable solution. Any suggestions would be greatly appreciated.