Skip to content

Commit fb2cd82

Browse files
authored
fix(#2342): navigating to custom route shows blank page (#2343)
1 parent 52a59f5 commit fb2cd82

File tree

6 files changed

+92
-82
lines changed

6 files changed

+92
-82
lines changed

spring-boot-admin-server-ui/src/main/frontend/composables/ViewRegistry.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import ViewRegistry from '../viewRegistry.js';
2+
import eventBus from '@/services/bus';
3+
import { debounce } from 'lodash-es';
4+
5+
export const CUSTOM_ROUTES_ADDED_EVENT = 'custom-routes-added';
26

37
let viewRegistry;
48

@@ -9,6 +13,10 @@ export function createViewRegistry() {
913
return viewRegistry;
1014
}
1115

16+
const emitCustomRouteAddedEvent = debounce(() => {
17+
eventBus.emit(CUSTOM_ROUTES_ADDED_EVENT);
18+
});
19+
1220
export function useViewRegistry() {
1321
return {
1422
views: viewRegistry.views,
@@ -21,17 +29,19 @@ export function useViewRegistry() {
2129
name: view.name,
2230
component: view.component,
2331
props: view.props,
24-
meta: { view: view },
32+
meta: { view: view }
2533
});
2634
} else {
2735
viewRegistry.router.addRoute({
2836
path: view.path,
2937
name: view.name,
3038
component: view.component,
3139
props: view.props,
32-
meta: { view: view },
40+
meta: { view: view }
3341
});
3442
}
35-
},
43+
44+
emitCustomRouteAddedEvent();
45+
}
3646
};
3747
}

spring-boot-admin-server-ui/src/main/frontend/index.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ import { createApp, h, onBeforeMount, onBeforeUnmount, reactive } from 'vue';
2020
import { useI18n } from 'vue-i18n';
2121

2222

23-
2423
import './index.css';
2524

2625

27-
2826
import components from './components';
29-
import { createViewRegistry, useViewRegistry } from './composables/ViewRegistry.js';
27+
import { createViewRegistry, CUSTOM_ROUTES_ADDED_EVENT, useViewRegistry } from './composables/ViewRegistry.js';
3028
import { createApplicationStore, useApplicationStore } from './composables/useApplicationStore.js';
3129
import i18n from './i18n';
3230
import { worker } from './mocks/browser';
@@ -35,6 +33,8 @@ import SbaModalPlugin from './plugins/modal';
3533
import sbaConfig from './sba-config.js';
3634
import sbaShell from './shell/index.vue';
3735
import views from './views';
36+
import eventBus from '@/services/bus';
37+
import { useRoute, useRouter } from 'vue-router';
3838

3939

4040
const applicationStore = createApplicationStore();
@@ -48,7 +48,7 @@ globalThis.SBA.use = ({ install }) => {
4848
install({
4949
viewRegistry: globalThis.SBA.viewRegistry,
5050
applicationStore: globalThis.SBA.useApplicationStore,
51-
i18n: i18n.global,
51+
i18n: i18n.global
5252
});
5353
};
5454

@@ -65,29 +65,24 @@ const installables = [Notifications, ...views];
6565
if (process.env.NODE_ENV === 'development') {
6666
worker.start({
6767
serviceWorker: {
68-
url: './mockServiceWorker.js',
69-
},
68+
url: './mockServiceWorker.js'
69+
}
7070
});
7171
}
7272

7373
installables.forEach((installable) => {
7474
installable.install({
7575
viewRegistry,
76-
applicationStore,
76+
applicationStore
7777
});
7878
});
7979

8080
const app = createApp({
8181
setup() {
82-
const { applications, applicationsInitialized, error } =
83-
useApplicationStore();
82+
const router = useRouter();
83+
const route = useRoute();
84+
const { applications, applicationsInitialized, error } = useApplicationStore();
8485
const { t } = useI18n();
85-
let props = reactive({
86-
applications,
87-
applicationsInitialized,
88-
error,
89-
t,
90-
});
9186

9287
onBeforeMount(() => {
9388
applicationStore.start();
@@ -97,14 +92,25 @@ const app = createApp({
9792
applicationStore.stop();
9893
});
9994

100-
return () => h(sbaShell, props);
101-
},
95+
let routesAddedEventHandler = async () => {
96+
eventBus.off(CUSTOM_ROUTES_ADDED_EVENT, routesAddedEventHandler);
97+
await router.replace(route);
98+
};
99+
eventBus.on(CUSTOM_ROUTES_ADDED_EVENT, routesAddedEventHandler);
100+
101+
return () => h(sbaShell, reactive({
102+
applications,
103+
applicationsInitialized,
104+
error,
105+
t
106+
}));
107+
}
102108
});
103109

104110
app.use(i18n);
105111
app.use(components);
106112
app.use(NotificationcenterPlugin, {
107-
duration: 10_000,
113+
duration: 10_000
108114
});
109115
app.use(SbaModalPlugin, { i18n });
110116
app.use(viewRegistry.createRouter());
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
<template>
2-
<div class="flex gap-1 w-full justify-end">
3-
<sba-button primary @click="() => close(true)" v-text="labelOk" />
2+
<div class='flex gap-1 w-full justify-end'>
3+
<sba-button primary @click='() => close(true)' v-text='labelOk' />
44
<sba-button
5-
class="button"
6-
@click="() => close(false)"
7-
v-text="labelCancel"
5+
class='button'
6+
@click='() => close(false)'
7+
v-text='labelCancel'
88
/>
99
</div>
1010
</template>
1111

1212
<script>
1313
import SbaButton from '@/components/sba-button';
1414
15-
import eventBus from '@/plugins/modal/bus';
15+
import eventBus from '@/services/bus';
1616
1717
export default {
1818
components: { SbaButton },
1919
props: {
2020
labelCancel: {
2121
type: String,
22-
required: true,
22+
required: true
2323
},
2424
labelOk: {
2525
type: String,
26-
required: true,
27-
},
26+
required: true
27+
}
2828
},
2929
methods: {
3030
close(result) {
3131
eventBus.emit('sba-modal-close', result);
32-
},
33-
},
32+
}
33+
}
3434
};
3535
</script>
Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
<template>
22
<TransitionRoot
3-
ref="root"
4-
:show="isOpen"
3+
ref='root'
4+
:show='isOpen'
55
appear
6-
as="template"
7-
@close="closeModal"
6+
as='template'
7+
@close='closeModal'
88
>
9-
<Dialog as="div" class="relative z-10 modal">
9+
<Dialog as='div' class='relative z-10 modal'>
1010
<TransitionChild
11-
as="template"
12-
enter="duration-300 ease-out"
13-
enter-from="opacity-0"
14-
enter-to="opacity-100"
15-
leave="duration-200 ease-in"
16-
leave-from="opacity-100"
17-
leave-to="opacity-0"
11+
as='template'
12+
enter='duration-300 ease-out'
13+
enter-from='opacity-0'
14+
enter-to='opacity-100'
15+
leave='duration-200 ease-in'
16+
leave-from='opacity-100'
17+
leave-to='opacity-0'
1818
>
19-
<div class="fixed inset-0 bg-black bg-opacity-25" />
19+
<div class='fixed inset-0 bg-black bg-opacity-25' />
2020
</TransitionChild>
2121

22-
<div class="fixed inset-0 overflow-y-auto">
22+
<div class='fixed inset-0 overflow-y-auto'>
2323
<div
24-
class="flex min-h-full items-center justify-center p-4 text-center"
24+
class='flex min-h-full items-center justify-center p-4 text-center'
2525
>
2626
<TransitionChild
27-
as="template"
28-
enter="duration-300 ease-out"
29-
enter-from="opacity-0 scale-95"
30-
enter-to="opacity-100 scale-100"
31-
leave="duration-200 ease-in"
32-
leave-from="opacity-100 scale-100"
33-
leave-to="opacity-0 scale-95"
27+
as='template'
28+
enter='duration-300 ease-out'
29+
enter-from='opacity-0 scale-95'
30+
enter-to='opacity-100 scale-100'
31+
leave='duration-200 ease-in'
32+
leave-from='opacity-100 scale-100'
33+
leave-to='opacity-0 scale-95'
3434
>
3535
<DialogPanel
36-
class="w-full max-w-md transform overflow-hidden rounded bg-white p-6 text-left align-middle shadow-xl transition-all"
36+
class='w-full max-w-md transform overflow-hidden rounded bg-white p-6 text-left align-middle shadow-xl transition-all'
3737
>
3838
<DialogTitle
39-
as="h3"
40-
class="text-lg font-medium leading-6 text-gray-900 flex justify-between"
39+
as='h3'
40+
class='text-lg font-medium leading-6 text-gray-900 flex justify-between'
4141
>
4242
{{ title }}
4343
</DialogTitle>
44-
<div class="mt-2 mb-2">
45-
<slot name="body" />
44+
<div class='mt-2 mb-2'>
45+
<slot name='body' />
4646
</div>
47-
<div class="mt-4">
48-
<slot name="buttons" />
47+
<div class='mt-4'>
48+
<slot name='buttons' />
4949
</div>
5050
</DialogPanel>
5151
</TransitionChild>
@@ -56,35 +56,29 @@
5656
</template>
5757

5858
<script>
59-
import {
60-
Dialog,
61-
DialogPanel,
62-
DialogTitle,
63-
TransitionChild,
64-
TransitionRoot,
65-
} from '@headlessui/vue';
59+
import { Dialog, DialogPanel, DialogTitle, TransitionChild, TransitionRoot } from '@headlessui/vue';
6660
import { defineComponent, ref } from 'vue';
6761
68-
import eventBus from '@/plugins/modal/bus';
62+
import eventBus from '@/services/bus';
6963
7064
export default defineComponent({
7165
components: {
7266
Dialog,
7367
DialogPanel,
7468
DialogTitle,
7569
TransitionRoot,
76-
TransitionChild,
70+
TransitionChild
7771
},
7872
props: {
7973
title: {
8074
type: String,
81-
required: true,
82-
},
75+
required: true
76+
}
8377
},
8478
emits: ['close'],
8579
setup() {
8680
return {
87-
isOpen: ref(true),
81+
isOpen: ref(true)
8882
};
8983
},
9084
mounted() {
@@ -96,7 +90,7 @@ export default defineComponent({
9690
methods: {
9791
closeModal() {
9892
this.isOpen = false;
99-
},
100-
},
93+
}
94+
}
10195
});
10296
</script>

spring-boot-admin-server-ui/src/main/frontend/plugins/modal/api.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { h } from 'vue';
22

33
import ConfirmButtons from './ConfirmButtons';
44
import Modal from './Modal';
5-
import eventBus from './bus';
65
import { createComponent } from './helpers';
6+
import eventBus from '@/services/bus';
77

88
export const useModal = (globalProps = {}) => {
99
const t =
1010
globalProps.i18n?.global.t ||
11-
function (value) {
11+
function(value) {
1212
return value;
1313
};
1414

@@ -18,7 +18,7 @@ export const useModal = (globalProps = {}) => {
1818
if (typeof options === 'string') title = options;
1919

2020
const defaultProps = {
21-
title,
21+
title
2222
};
2323

2424
const propsData = Object.assign({}, defaultProps, globalProps, options);
@@ -29,7 +29,7 @@ export const useModal = (globalProps = {}) => {
2929
h(
3030
'span',
3131
{
32-
innerHTML: body,
32+
innerHTML: body
3333
},
3434
[]
3535
);
@@ -40,9 +40,9 @@ export const useModal = (globalProps = {}) => {
4040
buttons: () =>
4141
h(ConfirmButtons, {
4242
labelOk: t('term.ok'),
43-
labelCancel: t('term.cancel'),
43+
labelCancel: t('term.cancel')
4444
}),
45-
body: bodyFn,
45+
body: bodyFn
4646
}
4747
);
4848

@@ -52,6 +52,6 @@ export const useModal = (globalProps = {}) => {
5252
resolve(result);
5353
});
5454
});
55-
},
55+
}
5656
};
5757
};

0 commit comments

Comments
 (0)