Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Restructure share routes to fix client-side navigation
Mike Caoc9e14f3bce01
diff --git a/src/app/share/ShareProvider.tsx b/src/app/share/ShareProvider.tsxindex 5b0ca12e3..9862a9742 100644--- a/src/app/share/ShareProvider.tsx+++ b/src/app/share/ShareProvider.tsx@@ -7,6 +7,7 @@ import type { WhiteLabel } from '@/lib/types';export interface ShareData {shareId: string;+ slug: string;websiteId: string;parameters: any;token: string;@@ -31,8 +32,8 @@ const ALL_SECTION_IDS = ['attribution',];-export function ShareProvider({ shareId, children }: { shareId: string; children: ReactNode }) {- const { share, isLoading, isFetching } = useShareTokenQuery(shareId);+export function ShareProvider({ slug, children }: { slug: string; children: ReactNode }) {+ const { share, isLoading, isFetching } = useShareTokenQuery(slug);const router = useRouter();const pathname = usePathname();const path = pathname.split('/')[3];@@ -48,9 +49,9 @@ export function ShareProvider({ shareId, children }: { shareId: string; childrenuseEffect(() => {if (shouldRedirect) {- router.replace(`/share/${shareId}/${allowedSections[0]}`);+ router.replace(`/share/${slug}/${allowedSections[0]}`);}- }, [shouldRedirect, shareId, allowedSections, router]);+ }, [shouldRedirect, slug, allowedSections, router]);if (isFetching && isLoading) {return <Loading placement="absolute" />;@@ -60,5 +61,5 @@ export function ShareProvider({ shareId, children }: { shareId: string; childrenreturn null;}- return <ShareContext.Provider value={share}>{children}</ShareContext.Provider>;+ return <ShareContext.Provider value={{ ...share, slug }}>{children}</ShareContext.Provider>;}diff --git a/src/app/share/[...shareId]/ShareFooter.tsx b/src/app/share/[...shareId]/ShareFooter.tsxdeleted file mode 100644index 5348ac63c..000000000--- a/src/app/share/[...shareId]/ShareFooter.tsx+++ /dev/null@@ -1,23 +0,0 @@-import { Row, Text } from '@umami/react-zen';-import { CURRENT_VERSION, HOMEPAGE_URL } from '@/lib/constants';-import type { WhiteLabel } from '@/lib/types';--export function ShareFooter({ whiteLabel }: { whiteLabel?: WhiteLabel }) {- if (whiteLabel) {- return (- <Row as="footer" paddingY="6" justifyContent="flex-end">- <a href={whiteLabel.url} target="_blank">- <Text weight="bold">{whiteLabel.name}</Text>- </a>- </Row>- );- }-- return (- <Row as="footer" paddingY="6" justifyContent="flex-end">- <a href={HOMEPAGE_URL} target="_blank">- <Text weight="bold">umami</Text> {`v${CURRENT_VERSION}`}- </a>- </Row>- );-}diff --git a/src/app/share/[...shareId]/ShareHeader.tsx b/src/app/share/[...shareId]/ShareHeader.tsxdeleted file mode 100644index abd8511df..000000000--- a/src/app/share/[...shareId]/ShareHeader.tsx+++ /dev/null@@ -1,33 +0,0 @@-import { Icon, Row, Text, ThemeButton } from '@umami/react-zen';-import { LanguageButton } from '@/components/input/LanguageButton';-import { PreferencesButton } from '@/components/input/PreferencesButton';-import { Logo } from '@/components/svg';-import type { WhiteLabel } from '@/lib/types';--export function ShareHeader({ whiteLabel }: { whiteLabel?: WhiteLabel }) {- const logoUrl = whiteLabel?.url || 'https://umami.is';- const logoName = whiteLabel?.name || 'umami';- const logoImage = whiteLabel?.image;-- return (- <Row as="header" justifyContent="space-between" alignItems="center" paddingY="3">- <a href={logoUrl} target="_blank" rel="noopener">- <Row alignItems="center" gap>- {logoImage ? (- <img src={logoImage} alt={logoName} style={{ height: 24 }} />- ) : (- <Icon>- <Logo />- </Icon>- )}- <Text weight="bold">{logoName}</Text>- </Row>- </a>- <Row alignItems="center" gap>- <ThemeButton />- <LanguageButton />- <PreferencesButton />- </Row>- </Row>- );-}diff --git a/src/app/share/[...shareId]/page.tsx b/src/app/share/[...shareId]/page.tsxdeleted file mode 100644index f21e19794..000000000--- a/src/app/share/[...shareId]/page.tsx+++ /dev/null@@ -1,13 +0,0 @@-import { ShareProvider } from '@/app/share/ShareProvider';-import { SharePage } from './SharePage';--export default async function ({ params }: { params: Promise<{ shareId: string[] }> }) {- const { shareId } = await params;- const [slug] = shareId;-- return (- <ShareProvider shareId={slug}>- <SharePage />- </ShareProvider>- );-}diff --git a/src/app/share/[...shareId]/ShareNav.tsx b/src/app/share/[slug]/[[...path]]/ShareNav.tsxsimilarity index 97%rename from src/app/share/[...shareId]/ShareNav.tsxrename to src/app/share/[slug]/[[...path]]/ShareNav.tsxindex 171539ac4..fa100b177 100644--- a/src/app/share/[...shareId]/ShareNav.tsx+++ b/src/app/share/[slug]/[[...path]]/ShareNav.tsx@@ -10,13 +10,13 @@ export function ShareNav({ onItemClick }: { onItemClick?: () => void }) {const share = useShare();const { formatMessage, labels } = useMessages();const { pathname } = useNavigation();- const { shareId, parameters, whiteLabel } = share;+ const { slug, parameters, whiteLabel } = share;const logoUrl = whiteLabel?.url || 'https://umami.is';const logoName = whiteLabel?.name || 'umami';const logoImage = whiteLabel?.image;- const renderPath = (path: string) => `/share/${shareId}${path}`;+ const renderPath = (path: string) => `/share/${slug}${path}`;const allItems = [{diff --git a/src/app/share/[...shareId]/SharePage.tsx b/src/app/share/[slug]/[[...path]]/SharePage.tsxsimilarity index 100%rename from src/app/share/[...shareId]/SharePage.tsxrename to src/app/share/[slug]/[[...path]]/SharePage.tsxdiff --git a/src/app/share/[slug]/[[...path]]/page.tsx b/src/app/share/[slug]/[[...path]]/page.tsxnew file mode 100644index 000000000..872cf2678--- /dev/null+++ b/src/app/share/[slug]/[[...path]]/page.tsx@@ -0,0 +1,5 @@+import { SharePage } from './SharePage';++export default function () {+ return <SharePage />;+}diff --git a/src/app/share/[slug]/layout.tsx b/src/app/share/[slug]/layout.tsxnew file mode 100644index 000000000..7a5f45990--- /dev/null+++ b/src/app/share/[slug]/layout.tsx@@ -0,0 +1,13 @@+import { ShareProvider } from '@/app/share/ShareProvider';++export default async function ({+ params,+ children,+}: {+ params: Promise<{ slug: string }>;+ children: React.ReactNode;+}) {+ const { slug } = await params;++ return <ShareProvider slug={slug}>{children}</ShareProvider>;+}