🧪 类型化路由

阶段: 原型

提供了一种在应用程序中构建 URL 的类型安全方式。

安装

  1. npm install github:BuilderIo/qwik-labs-build#main
  2. 更新 vite.config.ts 文件
    // ...
    import { qwikTypes } from '@builder.io/qwik-labs/vite'; 
     
    export default defineConfig(() => {
      return {
        plugins: [
         // ...
         qwikTypes() // <== 将 `qwikTypes()` 添加到插件列表中
        ],
        // ...
      };
    });
  3. 运行构建命令,以生成 ~/routes.gen.d.ts~/routes.config.tsx 文件。
  4. 创建类型安全的链接:
    import { AppLink } from '~/routes.config';
     
    export default component$(() => {
      // ...
      return (
        // ...
        <AppLink route="/your/[appParam]/link/" param:appParam={"some-value"}>
          链接文本
        </AppLink>
      );
    });

Contributors

Thanks to all the contributors who have helped make this documentation better!

  • mhevery