Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(site): preserve scroll for query-based album viewers

Timothy Yin005b3ff32676
diff --git a/apps/site/app/router.options.ts b/apps/site/app/router.options.ts
index f2eb6711..52a2329a 100644
--- a/apps/site/app/router.options.ts
+++ b/apps/site/app/router.options.ts
@@ -10,6 +10,16 @@ export default <RouterConfig>{
return false
}
+ // Album viewers use ?photo= on the same route instead of the slug page.
+ if (
+ to.path === from.path &&
+ to.path.startsWith('/albums/') &&
+ (typeof to.query?.photo === 'string' ||
+ typeof from.query?.photo === 'string') &&
+ to.hash === from.hash
+ )
+ return false
+
if (
from.name === 'slug' &&
!to.hash &&
diff --git a/tests/site-viewer-navigation.test.ts b/tests/site-viewer-navigation.test.ts
index e5531724..2b16ac61 100644
--- a/tests/site-viewer-navigation.test.ts
+++ b/tests/site-viewer-navigation.test.ts
@@ -20,8 +20,18 @@ test('Site viewer route keeps scroll on open/close and preserves normal navigati
{},
).default as {
scrollBehavior(
- to: { name?: string; path?: string; hash?: string },
- from: { name?: string; path?: string },
+ to: {
+ name?: string
+ path?: string
+ hash?: string
+ query?: { photo?: string }
+ },
+ from: {
+ name?: string
+ path?: string
+ hash?: string
+ query?: { photo?: string }
+ },
saved: unknown,
): unknown
}
@@ -61,6 +71,34 @@ test('Site viewer route keeps scroll on open/close and preserves normal navigati
),
{ el: '#summer' },
)
+ assert.equal(
+ router.scrollBehavior(
+ { path: '/albums/summer', query: { photo: 'one' } },
+ { path: '/albums/summer' },
+ null,
+ ),
+ false,
+ )
+ assert.equal(
+ router.scrollBehavior(
+ { path: '/albums/summer' },
+ { path: '/albums/summer', query: { photo: 'one' } },
+ null,
+ ),
+ false,
+ )
+ assert.deepEqual(
+ JSON.parse(
+ JSON.stringify(
+ router.scrollBehavior(
+ { path: '/albums/winter' },
+ { path: '/albums/summer', query: { photo: 'one' } },
+ null,
+ ),
+ ),
+ ),
+ { top: 0 },
+ )
const saved = { left: 0, top: 900 }
assert.equal(
router.scrollBehavior({ path: '/' }, { name: 'slug' }, saved),