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.

circle-info

Navigation helpers are router-agnostic. You implement them using your preferred routing library (React Router, Next.js Router, etc.).

How It Works

  1. Shell defines a navigate function and passes it to AppShellProvider

  2. Client calls navigation.navigate({ path: '/some-path' })

  3. Shell receives the navigation request via framebus

  4. 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

Property
Type
Description

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:

circle-info

For detailed information about using navigation on the client side, see the Client Application documentation.

Advanced Usage

Handling External Navigation

You may want to handle external URLs differently:

Query parameters can be included in the path:

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

Last updated

Was this helpful?