Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Latest commit

 

History

History
73 lines (61 loc) · 2.07 KB

Routing-And-Navigation.md

File metadata and controls

73 lines (61 loc) · 2.07 KB

👈 Return to Overview

Routing and Navigation

One App contains a single route <ModuleRoute moduleName={root-module-name}/> which loads the root-module configured by root-module-name. This is what makes the root module the entry point to your application. As One App does not set a path by default, the root module itself is required to have at least a single route with a path.

import { Route } from '@americanexpress/one-app-router';

export function RootModule({ children, config }) {
  return <h1>Hello World!</h1>;
}
RootModule.childRoutes = <Route path="/" />;

As your application grows, you can also take advantage of Holocron's ModuleRoute to load other modules.

import { Route } from '@americanexpress/one-app-router';
import ModuleRoute from 'holocron-module-route';

export function RootModule({ children, config }) {
  return (
    <React.Fragment>
      { /* Root module UI */ }
      { children }
    </React.Fragment>
  );
}
RootModule.childRoutes = [
  <Route key="/" path="/" component={() => <h1>Hello World</h1>} />,
  <ModuleRoute key="child" path="child" moduleName="child-module" />,
];

To allow users to navigate around your application you can use Link provided by One App Router.

import { Link, Route } from '@americanexpress/one-app-router';
import ModuleRoute from 'holocron-module-route';

export function RootModule({ children, config }) {
  return (
    <React.Fragment>
      <nav>
        <Link to="/">
          Home
        </Link>
        <Link to="/child">
          Home
        </Link>
      </nav>
      { children }
    </React.Fragment>
  );
}
RootModule.childRoutes = [
  <Route key="/" path="/" component={() => <h1>Hello World</h1>} />,
  <ModuleRoute key="child" path="child" moduleName="child-module" />,
];

📘 More Information

☝️ Return To Top