icejs Router Plugin

2.1.3 · maintenance · verified Tue Apr 21

build-plugin-ice-router provides comprehensive routing capabilities for the icejs framework. At its current stable version 2.1.3, it supports both convention-based routing, automatically generating routes from the `src/pages` directory structure, and configuration-based routing, allowing developers to define routes explicitly in `src/routes.[ts|js]`. Key differentiators include built-in support for nested layouts (using `_layout.tsx`), dynamic route parameters (e.g., `/$uid.tsx` for `/app/:uid`), and optional dynamic parameters (`/$uid$.tsx` for `/app/:uid?`). It also offers dedicated features for global layouts via `src/layouts/index.tsx` and 404 error pages via `src/pages/404.tsx`. This plugin is primarily associated with the icejs v2 ecosystem. The broader Alibaba/ICE framework has evolved to `@ice/app` in v3, which introduces a potentially different plugin system and core architecture. Users should be aware of this version distinction when integrating, as `build-plugin-ice-router` targets icejs v2.

Common errors

Warnings

Install

Imports

Quickstart

Sets up a minimal icejs application demonstrating convention-based routing. It defines a home page and an 'about' page, configured through `src/app.ts`.

/* src/app.ts */
import { runApp } from 'ice';
import type { IAppRouterConfig } from 'ice';

const appConfig: { router?: IAppRouterConfig } = {
  router: {
    type: 'browser',
    basename: '/',
    modifyRoutes: (routes) => {
      console.log('Routes generated:', routes);
      return routes;
    }
  }
};

runApp(appConfig);

/* src/pages/index.tsx */
import React from 'react';
import { Link } from 'ice'; // Example of a router-provided component

const Home = () => {
  return (
    <div>
      <h1>Welcome to icejs Home!</h1>
      <p>This is a convention-based route generated by build-plugin-ice-router.</p>
      <Link to="/about">Go to About</Link>
    </div>
  );
};

export default Home;

/* src/pages/About/index.tsx */
import React from 'react';

const About = () => {
  return (
    <div>
      <h2>About Page</h2>
      <p>Another convention-based route from `src/pages/About/index.tsx`.</p>
    </div>
  );
};

export default About;

/* build.json */
// Optional: Configure build-time router options, e.g., to ignore specific paths.
// {
//   "router": {
//     "ignorePaths": ["stores", "components"]
//   }
// }

view raw JSON →