Configuration
The @akinon/app-client library allows you to configure your application
through the config prop of the AppClientProvider component. This
configuration determines how your application behaves and interacts with the
main application shell.
Configuration Types
There are two main types of configurations, depending on whether your application is a fullpage application or a plugin:
FullpageApplicationConfigPluginApplicationConfig
Both of these extend the base ApplicationConfig interface.
Base ApplicationConfig
interface ApplicationConfig {
isDev: boolean;
forceRedirect?: boolean;
}| Property | Type | Description |
|---|---|---|
isDev | boolean | Indicates whether the application is running in development mode |
forceRedirect | boolean (optional) | If true, forces the application to load in an iframe if not already |
FullpageApplicationConfig
For fullpage applications, you need to provide additional configuration:
interface FullpageApplicationConfig extends ApplicationConfig {
menu: Array<...>; // Define the menu structure
navigation: {
navigate: (payload: { path: string }) => void;
};
}| Property | Type | Description |
|---|---|---|
menu | Array<...> | Defines the menu structure for the application |
navigation | Object | Contains the navigation function |
navigation.navigate | (payload: { path: string }) => void | Function to handle navigation within the application |
PluginApplicationConfig
For plugin applications, you can use the base ApplicationConfig or extend it
with plugin-specific options if needed.
Usage Example
Here’s an example of how to configure a fullpage application:
import React from 'react';
import {
AppClientProvider,
type FullpageApplicationConfig
} from '@akinon/app-client';
import App from './App';
const config: FullpageApplicationConfig = {
isDev: process.env.NODE_ENV === 'development',
forceRedirect: true,
menu: [
{ label: 'Dashboard', path: '/dashboard' },
{ label: 'Settings', path: '/settings' }
// Add more menu items as needed
],
navigation: {
navigate: ({ path }) => {
// Implement your navigation logic here
console.log(`Navigating to: ${path}`);
}
}
};
const Root = () => (
<AppClientProvider config={config}>
<App />
</AppClientProvider>
);
export default Root;Best Practices
-
Environment-based Configuration: Use environment variables or build-time constants to set the
isDevflag appropriately for different environments. -
Type Safety: When using TypeScript, always use the appropriate configuration type (
FullpageApplicationConfigorPluginApplicationConfig) to ensure type safety and catch potential errors early. -
Navigation Handling: Implement the
navigatefunction in a way that works well with your application’s routing system, whether you’re using React Router or another routing solution. -
Menu Structure: Design your menu structure carefully, considering the hierarchy and organization of your application’s pages and features.
-
Conditional Configuration: You can use conditional logic to adjust the configuration based on different factors, such as the environment or user roles.
By properly configuring your application, you ensure that it integrates smoothly with the main application shell and provides a consistent user experience across different parts of your micro-frontend architecture.