Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/with-fallback-element/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@ice/app';

export default defineConfig(() => ({
ssg: false,
}));
20 changes: 20 additions & 0 deletions examples/with-fallback-element/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@ice/example-with-fallback-element",
"private": true,
"version": "1.0.0",
"description": "Example demonstrating custom fallbackElement configuration in app.tsx",
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0",
"@ice/runtime": "workspace:*"
},
"devDependencies": {
"@ice/app": "workspace:*",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0"
},
"scripts": {
"start": "ice start",
"build": "ice build"
}
}
33 changes: 33 additions & 0 deletions examples/with-fallback-element/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { defineAppConfig } from 'ice';

// Custom fallback element.
const CustomFallback = () => (
<div
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '100vh',
fontSize: '18px',
color: '#666',
}}
>
<div>
<div>🔄 Loading...</div>
<div style={{ fontSize: '14px', marginTop: '8px' }}>
Custom fallback element from app.tsx configuration
</div>
</div>
</div>
);

export default defineAppConfig({
app: {
rootId: 'app',
},
router: {
type: 'hash',
fallbackElement: <CustomFallback />,
},
});
14 changes: 14 additions & 0 deletions examples/with-fallback-element/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

export default function Home() {
return (
<div>
<h2 style={{ textAlign: 'center', padding: '20px' }}>
Home Page
</h2>
<div style={{ textAlign: 'center' }}>
Welcome to the Home Page!
</div>
</div>
);
}
15 changes: 15 additions & 0 deletions examples/with-fallback-element/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { Link } from 'ice';

export default function Home() {
return (
<div>
<h2 style={{ textAlign: 'center', padding: '20px' }}>
Test Page
</h2>
<div style={{ textAlign: 'center' }}>
<Link to="/home">Go to Home Page</Link>
</div>
</div>
);
}
14 changes: 14 additions & 0 deletions examples/with-fallback-element/src/pages/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { useNavigation, Outlet } from 'ice';

export default function Home() {
const navigation = useNavigation();
// Use navigation state to determine loading status, and show loading indicator.
const isLoading = navigation.state === 'loading';
return (
<div>
{isLoading && (<div>loading</div>)}
<Outlet />
</div>
);
}
5 changes: 3 additions & 2 deletions packages/runtime/src/ClientRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function createRouterHistory(history: History, router: Router) {
let router: Router = null;
function ClientRouter(props: ClientAppRouterProps) {
const { Component, routerContext } = props;
const { revalidate } = useAppContext();
const { revalidate, appConfig } = useAppContext();

function clearRouter() {
if (router) {
Expand Down Expand Up @@ -57,7 +57,8 @@ function ClientRouter(props: ClientAppRouterProps) {

let element: React.ReactNode;
if (process.env.ICE_CORE_ROUTER === 'true') {
element = <RouterProvider router={router} fallbackElement={null} />;
const fallbackElement = appConfig?.router?.fallbackElement ?? null;
element = <RouterProvider router={router} fallbackElement={fallbackElement} />;
} else {
element = <Component />;
}
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/src/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const defaultAppConfig: AppConfig = {
},
router: {
type: 'browser',
fallbackElement: null,
},
};

Expand Down
1 change: 1 addition & 0 deletions packages/runtime/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface AppConfig {
type?: 'hash' | 'browser' | 'memory';
basename?: string;
initialEntries?: InitialEntry[];
fallbackElement?: React.ReactNode;
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/runtime/tests/appConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('AppConfig', () => {
strict: false,
},
router: {
fallbackElement: null,
type: 'browser',
},
});
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading