Skip to content

Commit 65d6f80

Browse files
committed
feat: test expo playground jump
1 parent f472b52 commit 65d6f80

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/connect-examples/expo-playground/app/entry.client.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ import DeviceMethodExecutePage from './routes/device-methods.$methodName';
3232
// Import styles
3333
import './tailwind.css';
3434

35-
// 根据环境确定 basename
36-
const basename = process.env.NODE_ENV === 'production' ? '/expo-playground' : '';
35+
// 运行时自动检测 basename:
36+
// - 若路径以 /expo-playground 开头,则使用 '/expo-playground'(GitHub Pages 子路径)
37+
// - 否则使用 ''(CDN 根路径或其他根部署)
38+
const basename = (() => {
39+
const segments = window.location.pathname.split('/').filter(Boolean);
40+
if (segments.length > 0) {
41+
return `/${segments[0]}`;
42+
}
43+
return '';
44+
})();
3745

3846
// 处理从404页面重定向过来的路径恢复
3947
function handleSpaRedirect() {
@@ -55,6 +63,8 @@ function handleSpaRedirect() {
5563
window.history.replaceState(null, '', redirectUrl);
5664
}
5765
}
66+
67+
// 保持 404 重定向的 sessionStorage 路由恢复(用于 GH Pages 子路径)
5868
}
5969

6070
// Layout wrapper component

packages/connect-examples/expo-playground/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module.exports = async (env, argv) => {
1818
path: path.resolve(__dirname, 'dist'),
1919
filename: isProduction ? '[name].[contenthash].js' : '[name].js',
2020
clean: true,
21-
publicPath: isProduction ? '/expo-playground/' : '/',
21+
// 使用 webpack5 的 auto,让资源在 GH Pages 子路径与 CDN 根路径都能正确加载
22+
publicPath: 'auto',
2223
},
2324

2425
resolve: {

0 commit comments

Comments
 (0)