Navigation
AppShell's navigation helpers allow micro-frontend applications to trigger navigation in the main application.
Overview
This enables clients to redirect users to different pages within the shell application without direct access to the shell's router.
How It Works
Shell defines a
navigatefunction and passes it toAppShellProviderClient calls
navigation.navigate({ path: '/some-path' })Shell receives the navigation request via framebus
Shell executes the navigation using its router
Usage
Pass the navigation prop to AppShellProvider:
import { AppShellProvider, type ShellNavigation } from '@akinon/app-shell';
import { useNavigate } from 'react-router';
const App = () => {
const routerNavigate = useNavigate();
const navigation: ShellNavigation = {
navigate: (payload) => {
routerNavigate(payload.path);
}
};
return (
<AppShellProvider
apps={registeredApps}
data={sharedData}
navigation={navigation}
actions={shellActions}
>
{/* Your shell application */}
</AppShellProvider>
);
};ShellNavigation Type
path
string
The target path to navigate to
id
number
Optional. Application ID for context
Implementation Examples
React Router
TanStack Router
With Application ID
You can use the optional id parameter to handle navigation with application context:
Using Navigation (Client Side)
Clients trigger navigation via the useAppClient hook:
Advanced Usage
Handling External Navigation
You may want to handle external URLs differently:
Navigation with Query Parameters
Query parameters can be included in the path:
Navigation with State
If you need to pass state data during navigation, use a combination of navigation and actions:
Best Practices
1. Keep Navigation Logic Simple
The navigation handler should focus on routing. Complex logic should be in actions.
2. Handle Unknown Paths Gracefully
Consider what happens when a client requests an invalid path:
3. Consider Navigation Timing
If clients navigate immediately on mount, ensure the shell is ready:
Next Steps
Data Sharing - Share data with clients
Actions - Define custom actions
Last updated
Was this helpful?

