CxJS

Routing

CxJS includes built-in routing for single-page applications. Define routes that render content based on the URL, navigate programmatically, and handle deep linking.

Both hash-based (#/path) and pushState based (/path) navigation modes are supported.

Key Components

ComponentDescription
RouteConditionally renders content when the URL matches a pattern
RedirectRouteAutomatically redirects when the URL matches
UrlHelper class for URL path manipulation and resolution
HistoryProgrammatic navigation with pushState, confirmations, and subscriptions

Basic Setup

import { Route } from "cx/widgets";
import { History } from "cx/ui";

// Connect History to store
History.connect(store, "url");

// Define routes
<Route route="~/" url={m.url}>
  <HomePage />
</Route>
<Route route="~/about" url={m.url}>
  <AboutPage />
</Route>

The ~/ prefix resolves to your application’s base path, making routes portable across different deployment paths.