Skip to content

Commit f5950fc

Browse files
committed
Add Navigation examples to 2025-10
1 parent bd0239c commit f5950fc

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

packages/ui-extensions/docs/surfaces/customer-account/reference/apis/navigation.doc.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,33 @@ const data: ReferenceEntityTemplateSchema = {
2828
],
2929
},
3030
},
31+
examples: {
32+
description: 'Navigation api examples',
33+
examples: [
34+
{
35+
codeblock: {
36+
title: 'Listening for navigation current entry events',
37+
tabs: [
38+
{
39+
code: '../examples/apis/navigation-event-listeners.example.jsx',
40+
language: 'jsx',
41+
},
42+
],
43+
},
44+
},
45+
{
46+
codeblock: {
47+
title: 'Navigating to native order index page',
48+
tabs: [
49+
{
50+
code: '../examples/apis/navigating-to-customer-account-page.example.jsx',
51+
language: 'jsx',
52+
},
53+
],
54+
},
55+
},
56+
],
57+
},
3158
related: [],
3259
};
3360

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import '@shopify/ui-extensions/preact';
2+
import {render} from 'preact';
3+
4+
export default async () => {
5+
render(<Extension />, document.body);
6+
};
7+
8+
function Extension() {
9+
return (
10+
<s-button
11+
onClick={() => {
12+
navigation.navigate(
13+
'shopify:customer-account/orders',
14+
);
15+
}}
16+
>
17+
Navigate to orders path
18+
</s-button>
19+
);
20+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import '@shopify/ui-extensions/preact';
2+
import {render} from 'preact';
3+
import {useState, useEffect} from 'preact/hooks';
4+
5+
export default async () => {
6+
render(<Extension />, document.body);
7+
};
8+
9+
function Extension() {
10+
const [currentEntryUrl, setCurrentEntryUrl] =
11+
useState(navigation.currentEntry.url);
12+
13+
useEffect(() => {
14+
function updateCurrentEntryUrl() {
15+
setCurrentEntryUrl(
16+
navigation.currentEntry.url,
17+
);
18+
}
19+
20+
navigation.addEventListener(
21+
'currententrychange',
22+
updateCurrentEntryUrl,
23+
);
24+
return () =>
25+
navigation.removeEventListener(
26+
'currententrychange',
27+
updateCurrentEntryUrl,
28+
);
29+
}, []);
30+
31+
if (currentEntryUrl === 'extension:/') {
32+
return <Wishlists />;
33+
} else if (
34+
currentEntryUrl.includes(
35+
'extension:/wishlist/',
36+
)
37+
) {
38+
return <WishlistItemDetails />;
39+
} else {
40+
return <NotFound />;
41+
}
42+
}
43+
44+
function Wishlists() {
45+
return (
46+
<s-page heading="Wishlist">
47+
<s-button
48+
slot="secondary-actions"
49+
href="extension:/wishlist/123"
50+
>
51+
Wishlist details
52+
</s-button>
53+
<s-text>Wishlist content</s-text>
54+
</s-page>
55+
);
56+
}
57+
58+
function WishlistItemDetails() {
59+
return (
60+
<s-page heading="Wishlist item details">
61+
<s-button
62+
slot="breadcrumb-actions"
63+
accessibilityLabel="Back to wishlists"
64+
href="extension:/"
65+
></s-button>
66+
<s-button
67+
slot="secondary-actions"
68+
href="extension:/"
69+
>
70+
Back to wishlists
71+
</s-button>
72+
<s-text>
73+
Wishlist item details content
74+
</s-text>
75+
</s-page>
76+
);
77+
}
78+
79+
function NotFound() {
80+
return (
81+
<s-stack>
82+
<s-heading>Resource Not found</s-heading>
83+
</s-stack>
84+
);
85+
}

0 commit comments

Comments
 (0)