Fix app switching — remount AppFrame on slug change so iframe src recomputes
This commit is contained in:
parent
24b08012e8
commit
9e5c415685
1 changed files with 9 additions and 2 deletions
11
src/App.tsx
11
src/App.tsx
|
|
@ -1,4 +1,4 @@
|
|||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'
|
||||
import { BrowserRouter, Routes, Route, Navigate, useParams } from 'react-router-dom'
|
||||
import { AuthGate } from './components/AuthGate'
|
||||
import { Login } from './pages/Login'
|
||||
import { Register } from './pages/Register'
|
||||
|
|
@ -9,6 +9,13 @@ import { AdminRoles } from './pages/AdminRoles'
|
|||
import { AdminDepartments } from './pages/AdminDepartments'
|
||||
import { AdminMonitor } from './pages/AdminMonitor'
|
||||
import { AdminSettings } from './pages/AdminSettings'
|
||||
import type { User } from './types'
|
||||
|
||||
// Force full remount of AppFrame when slug changes so initialSrc recomputes
|
||||
function AppFrameKeyed({ user }: { user: User }) {
|
||||
const { slug } = useParams<{ slug: string }>()
|
||||
return <AppFrame key={slug} user={user} />
|
||||
}
|
||||
|
||||
// The portal is only ever the top-level frame. If it finds itself loaded inside
|
||||
// an iframe, it means an app's path fell back to the portal (that app isn't
|
||||
|
|
@ -46,7 +53,7 @@ export default function App() {
|
|||
{user => (
|
||||
<Routes>
|
||||
<Route path="/" element={<Dashboard user={user} />} />
|
||||
<Route path="/app/:slug" element={<AppFrame user={user} />} />
|
||||
<Route path="/app/:slug" element={<AppFrameKeyed user={user} />} />
|
||||
<Route path="/admin/users" element={user.is_admin ? <AdminUsers user={user} /> : <Navigate to="/" />} />
|
||||
<Route path="/admin/roles" element={user.is_admin ? <AdminRoles user={user} /> : <Navigate to="/" />} />
|
||||
<Route path="/admin/departments" element={user.is_admin ? <AdminDepartments user={user} /> : <Navigate to="/" />} />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue