Skip to content

Commit 9ea22a8

Browse files
committed
fix: keep demo query after each navigation
1 parent 84a9b73 commit 9ea22a8

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/lib/Demo.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,25 @@ function insertCustomDemoStyles() {
125125
* Sets up a router guard to handle redirects for the demo environment.
126126
*/
127127
function rewriteDemoRoutes() {
128-
demoRouter.beforeEach((to, _from, next) => {
128+
demoRouter.beforeResolve(async (to, from, next) => {
129+
// Avoid displaying receive modal
129130
if (to.path.startsWith('/receive/') && !to.path.startsWith('/receive/nim')) {
130-
return next({
131-
path: `/${DemoModal.Fallback}`,
132-
query: { ...to.query, [DEMO_PARAM]: '' },
133-
})
131+
return next({ path: `/${DemoModal.Fallback}`, query: { ...to.query, [DEMO_PARAM]: '' } });
134132
}
133+
135134
// Redirect certain known paths to the Buy demo modal
136135
if (to.path === '/buy') {
137-
return next({
138-
path: `/${DemoModal.Buy}`,
139-
query: { ...to.query, [DEMO_PARAM]: '' },
140-
});
136+
return next({ path: `/${DemoModal.Buy}`, query: { ...to.query, [DEMO_PARAM]: '' }, replace: true });
141137
}
142138

143-
// Ensure the ?demo param is in place
144-
if (to.query.demo === '') return next();
145-
return next({ path: to.path, query: { ...to.query, [DEMO_PARAM]: '' } });
139+
// FIXME: When clicking the hamburger menu, nothing opens
140+
if (to.query[DEMO_PARAM] === undefined) {
141+
next({ path: to.path, query: { ...to.query, [DEMO_PARAM]: '' }, replace: true });
142+
}
143+
144+
next();
146145
});
146+
147147
}
148148

149149
/**
@@ -1945,29 +1945,29 @@ function observeReceiveModal(processedElements: WeakSet<Element>) {
19451945
// Find the receive modal
19461946
const receiveModal = document.querySelector('.receive-modal');
19471947
if (!receiveModal) return;
1948-
1948+
19491949
// Look for buttons that should redirect to the fallback modal
19501950
const buttons = receiveModal.querySelectorAll('.nq-button-s, .qr-button');
1951-
1951+
19521952
buttons.forEach(button => {
19531953
// Skip if we've already processed this button
19541954
if (processedElements.has(button)) return;
1955-
1955+
19561956
// Mark as processed to avoid adding multiple listeners
19571957
processedElements.add(button);
1958-
1958+
19591959
// Replace the original click handler with our redirect
19601960
button.addEventListener('click', (event) => {
19611961
// Prevent the default action and stop propagation
19621962
event.preventDefault();
19631963
event.stopPropagation();
1964-
1964+
19651965
// Redirect to the fallback modal
19661966
demoRouter.replace({
19671967
path: `/${DemoModal.Fallback}`,
19681968
query: { [DEMO_PARAM]: '' },
19691969
});
1970-
1970+
19711971
console.log('[Demo] Redirected receive modal button click to fallback modal');
19721972
}, true); // Use capture to intercept the event before other handlers
19731973
});

0 commit comments

Comments
 (0)