File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
packages/connect-examples/expo-playground Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,16 @@ import DeviceMethodExecutePage from './routes/device-methods.$methodName';
3232// Import styles
3333import './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页面重定向过来的路径恢复
3947function 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
Original file line number Diff line number Diff 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 : {
You can’t perform that action at this time.
0 commit comments