Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show 404 page for non-existent routes #1789

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

import { createRouter, createWebHistory } from 'vue-router'
import { Empty } from '@openc3/vue-common/components'
import { NotFound } from '@openc3/vue-common/components'
import { Login } from '@openc3/vue-common/tools/base'

export default createRouter({
Expand All @@ -33,10 +33,9 @@ export default createRouter({
component: Login,
},
{
// Empty component for all other routes to avoid VueRouter warnings, since all other routes are handled by single-spa
path: '/:pathMatch(.*)*',
name: '',
component: Empty,
component: NotFound,
},
],
})

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
# Copyright 2023 OpenC3, Inc.
# Copyright 2024 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
Expand All @@ -17,11 +17,47 @@
-->

<template>
<v-card>
<v-card-title>404 Not Found Error</v-card-title>
<v-card-text
>The requested URL <code>{{ $route.fullPath }}</code> was not
routable.</v-card-text
>
<v-card v-if="show">
<v-card-title> 404 Not Found </v-card-title>
<v-card-text class="d-flex align-center mt-3">
The requested URL
<code class="mx-1"> {{ $route.fullPath }} </code>
was not routable.
<span class="text-h3 mx-1"> 🦄 </span>
</v-card-text>
</v-card>
</template>

<script>
import { getMountedApps } from 'single-spa'

const SINGLE_SPA_APP_CHANGE_EVENT = 'single-spa:app-change'

// This component is actually always loaded for every route other than /login
// because of the catch-all path in tool-base's router, so we need logic to
// hide it when a tool is loaded.
export default {
data() {
return {
show: false,
}
},
created() {
window.addEventListener(SINGLE_SPA_APP_CHANGE_EVENT, this.handleAppChange)
},
mounted() {
// Give single-spa some time to get an app mounted to avoid flashing this
setTimeout(() => {
this.show = getMountedApps().length === 0
}, 150)
},
unmounted() {
window.removeEventListener(SINGLE_SPA_APP_CHANGE_EVENT, this.handleAppChange)
},
methods: {
handleAppChange: function (event) {
this.show = !event.detail.appsByNewStatus.MOUNTED
},
},
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import CriticalCmdDialog from './CriticalCmdDialog.vue'
import { DataViewerComponent, DataViewerHistoryComponent } from './dataviewer'
import DetailsDialog from './DetailsDialog.vue'
import EditScreenDialog from './EditScreenDialog.vue'
import Empty from './Empty.vue'
import EnvironmentChooser from './EnvironmentChooser.vue'
import EnvironmentDialog from './EnvironmentDialog.vue'
import FileOpenSaveDialog from './FileOpenSaveDialog.vue'
Expand Down Expand Up @@ -52,7 +51,6 @@ export {
DataViewerHistoryComponent,
DetailsDialog,
EditScreenDialog,
Empty,
EnvironmentChooser,
EnvironmentDialog,
FileOpenSaveDialog,
Expand Down
Loading