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.
npm install build-plugin-ice-routerVerified import paths — ran on the pinned version, not inferred.
Sets up a minimal icejs application demonstrating convention-based routing. It defines a home page and an 'about' page, configured through `src/app.ts`.
For `@ice/app` v3 projects, refer to the official `@ice/app` documentation for its routing solution, typically involving `@ice/plugin-router`. Remove `build-plugin-ice-router` from your `package.json` and build configuration.
If you intend to use convention-based routing, ensure no `src/routes.[ts|js]` file exists. If using configuration-based, ensure all desired routes are explicitly defined in `src/routes.[ts|js]`.
To enforce case sensitivity, add `"router": { "caseSensitive": true }` to your `build.json`. Ensure consistent casing in your file/directory names and route links.Carefully review the dynamic route naming conventions in the documentation. Test dynamic route paths thoroughly to ensure they resolve correctly.
Verify that your page components are correctly placed in `src/pages` for convention-based routing, or that your `src/routes.ts` file accurately defines the path. Ensure `src/pages/404.tsx` (or `src/pages/404/index.tsx`) exists for a custom 404 page.
Ensure `src/app.ts` includes an `appConfig` object with a properly structured `router` property, for example: `{ router: { type: 'browser', basename: '/' } }`.Install the `ice` package via `npm install ice` or `yarn add ice`. If already installed, try clearing your package manager cache and reinstalling dependencies (`npm cache clean --force && rm -rf node_modules && npm install`).