This commit is contained in:
Copilot 2025-09-25 22:49:53 +09:00 committed by GitHub
commit d8334f0b6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -106,6 +106,11 @@ export async function common(createVue: () => Promise<App<Element>>) {
window.history.replaceState(null, '', window.location.href.replace('#pswp', '')); window.history.replaceState(null, '', window.location.href.replace('#pswp', ''));
} }
// URLに#folder-を含む場合は取り除くFolderPageView用
if (window.location.hash.startsWith('#folder-')) {
window.history.replaceState(null, '', window.location.href.replace(window.location.hash, ''));
}
// 一斉リロード // 一斉リロード
reloadChannel.addEventListener('message', path => { reloadChannel.addEventListener('message', path => {
if (path !== null) window.location.href = path; if (path !== null) window.location.href = path;

View File

@ -27,7 +27,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { onMounted, onUnmounted, ref } from 'vue';
import { claimZIndex } from '@/os.js'; import { claimZIndex } from '@/os.js';
import { prefer } from '@/preferences.js'; import { prefer } from '@/preferences.js';
@ -49,9 +49,34 @@ function closePage() {
} }
function onClosed() { function onClosed() {
// When closing, remove our history entry if we're still on our hash
if (window.location.hash === `#folder-${props.pageId}`) {
window.history.back();
}
emit('closed'); emit('closed');
} }
function popstateHandler(): void {
// If the hash is no longer our folder hash, close the page
if (window.location.hash !== `#folder-${props.pageId}`) {
closePage();
}
}
onMounted(() => {
// Push a new history state with a unique hash when the folder page opens
const folderHash = `#folder-${props.pageId}`;
window.history.pushState(null, '', folderHash);
// Listen for popstate events (browser back button)
window.addEventListener('popstate', popstateHandler);
});
onUnmounted(() => {
// Clean up the event listener
window.removeEventListener('popstate', popstateHandler);
});
</script> </script>
<style lang="scss" module> <style lang="scss" module>