Skip to content

Commit f115916

Browse files
fix(static-site): update baseUrl
1 parent 2c0dbf7 commit f115916

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/static-site/src/utils/baseUrl.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import { PagePaths } from '../routes/config';
22

33
export const getBaseUrl = () => {
44

5-
const pages = Object.values(PagePaths).filter((page) => page !== '/').map((page) => page.replace(/\//g, ''));
5+
const pages = Object.values(PagePaths)
6+
.filter((page) => page !== '/')
7+
.map((page) => page.replace(/\//g, ''));
68

79
if (typeof window === 'undefined') return '/';
810

911
const pathname = window.location.pathname;
1012

11-
const segments = pathname.split('/').filter(str=> str !== 'index.html');
13+
const segments = pathname.split('/')
14+
.filter(Boolean)
15+
.filter((segment) => !pages.includes(segment))
16+
.filter((segment) => segment.indexOf(".") === -1);
1217

13-
if (pages.includes(segments[0])) {
14-
segments.shift();
15-
}
16-
17-
return segments.length > 0 ? `/${segments[0]}` : '/';
18+
return `/${segments.join('/')}`;
1819

1920
};
2021

0 commit comments

Comments
 (0)