Skip to content

Commit 9f222f8

Browse files
committed
chore(greenhouse): allow enabling hashed routing mainly for PR Preview
1 parent 35990b7 commit 9f222f8

4 files changed

Lines changed: 10 additions & 4 deletions

File tree

apps/greenhouse/appProps.template.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"authIssuerUrl": "https://auth.backend.com/",
33
"authClientId": "client-id",
44
"currentHost": "https://assets.server.com/",
5-
"apiEndpoint": "https://api.greenhouse.com/"
5+
"apiEndpoint": "https://api.greenhouse.com/",
6+
"enableHashedRouting": false
67
}

apps/greenhouse/src/Shell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import React, { StrictMode } from "react"
7-
import { createRouter, RouterProvider } from "@tanstack/react-router"
7+
import { createBrowserHistory, createHashHistory, createRouter, RouterProvider } from "@tanstack/react-router"
88
import { AppShellProvider } from "@cloudoperators/juno-ui-components"
99
import { MessagesProvider } from "@cloudoperators/juno-messages-provider"
1010
import { decodeV2, encodeV2 } from "@cloudoperators/juno-url-state-provider"
@@ -52,6 +52,7 @@ const StyledShell = (props: AppProps) => {
5252
routeTree,
5353
context: { appProps: props },
5454
stringifySearch: encodeV2,
55+
history: props.enableHashedRouting ? createHashHistory() : createBrowserHistory(),
5556
parseSearch: (searchString) => {
5657
if (!props.enableHashedRouting) {
5758
return decodeV2(searchString)

apps/greenhouse/src/components/Extension.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as supernova from "@cloudoperators/juno-app-supernova"
88
import * as doop from "@cloudoperators/juno-app-doop"
99
import * as heureka from "@cloudoperators/juno-app-heureka"
1010
import * as admin from "../components/core-apps/org-admin"
11+
import { AppProps } from "../Shell"
1112

1213
const getApp = (appName: string) => {
1314
switch (appName) {
@@ -28,9 +29,10 @@ type ExtensionProps = {
2829
id: string
2930
config: any
3031
auth: any
32+
appProps: AppProps
3133
}
3234

33-
function Extension({ id, config, auth }: ExtensionProps) {
35+
function Extension({ id, config, auth, appProps }: ExtensionProps) {
3436
const appContainerRef = useRef<HTMLDivElement>(null)
3537
const app = getApp(config.name)
3638

@@ -47,6 +49,7 @@ function Extension({ id, config, auth }: ExtensionProps) {
4749
embedded: true,
4850
token: auth?.JWT,
4951
basePath: `/${config.id}`,
52+
enableHashedRouting: appProps?.enableHashedRouting || false,
5053
}
5154
: { auth: auth }),
5255
},

apps/greenhouse/src/routes/$extensionId.*.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ function RouteComponent() {
1919
// @ts-expect-error TS(2339): Property 'data' does not exist on type 'unknown'.
2020
const { data: auth } = useAuth()
2121
const { extensionId } = Route.useParams()
22+
const { appProps } = Route.useRouteContext()
2223
const appConfig = config[extensionId]
2324

2425
if (!appConfig) {
2526
return null
2627
}
2728

28-
return <Extension id={extensionId} config={appConfig} auth={auth} />
29+
return <Extension id={extensionId} config={appConfig} auth={auth} appProps={appProps} />
2930
}

0 commit comments

Comments
 (0)