feat(platform-web): preserve protocol in vehicle links

This commit is contained in:
lingniu
2026-07-04 01:15:39 +08:00
parent 8e5cb5b8c7
commit 657674f233
4 changed files with 41 additions and 15 deletions

View File

@@ -3,9 +3,10 @@ import { buildAppHash, parseAppHash } from './appRoute';
describe('parseAppHash', () => {
test('parses detail page keyword from hash query', () => {
expect(parseAppHash('#/detail?keyword=%E7%B2%A4AG18312')).toEqual({
expect(parseAppHash('#/detail?keyword=%E7%B2%A4AG18312&protocol=JT808')).toEqual({
page: 'detail',
keyword: '粤AG18312'
keyword: '粤AG18312',
protocol: 'JT808'
});
});
@@ -16,7 +17,7 @@ describe('parseAppHash', () => {
describe('buildAppHash', () => {
test('builds shareable vehicle page hash with encoded keyword', () => {
expect(buildAppHash({ page: 'history', keyword: '粤AG18312' })).toBe('#/history?keyword=%E7%B2%A4AG18312');
expect(buildAppHash({ page: 'history', keyword: '粤AG18312', protocol: 'GB32960' })).toBe('#/history?keyword=%E7%B2%A4AG18312&protocol=GB32960');
});
test('builds page-only hash when keyword is empty', () => {

View File

@@ -5,6 +5,7 @@ const pageKeys = new Set<PageKey>(['dashboard', 'vehicles', 'realtime', 'detail'
export type AppRoute = {
page?: PageKey;
keyword?: string;
protocol?: string;
};
export function parseAppHash(hash: string): AppRoute {
@@ -18,7 +19,8 @@ export function parseAppHash(hash: string): AppRoute {
}
const params = new URLSearchParams(queryPart);
const keyword = params.get('keyword')?.trim() || undefined;
return { page: pagePart as PageKey, keyword };
const protocol = params.get('protocol')?.trim() || undefined;
return { page: pagePart as PageKey, keyword, protocol };
}
export function buildAppHash(route: AppRoute): string {
@@ -28,6 +30,10 @@ export function buildAppHash(route: AppRoute): string {
if (keyword) {
params.set('keyword', keyword);
}
const protocol = route.protocol?.trim();
if (protocol) {
params.set('protocol', protocol);
}
const query = params.toString();
return query ? `#/${page}?${query}` : `#/${page}`;
}