4.2.1 • Published 4 months ago

astro-typesafe-routes v4.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Installation

  1. Add integration
npx astro add astro-typesafe-routes
  1. Start the Astro development server if it's not already running to run code generation
npm run dev

Manual Installation

  1. Install package
npm install -D astro-typesafe-routes
  1. Add integration to astro.config.mjs
import { defineConfig } from 'astro/config';
import astroTypesafeRoutes from "astro-typesafe-routes"

export default defineConfig({
    integrations: [
        astroTypesafeRoutes()
    ]
});
  1. Start the Astro development server if it's not already running to run code generation
npm run dev

Usage

Import the path function and use it as a drop-in replacement on links and anywhere else you would use a URL.

---
import { $path } from "astro-typesafe-routes";
---

<a href={$path("/posts/[postId]", { params: { postId: "1" } })}>
  Blog Post
</a>

The path function also accepts the optional fields search, hash and trailingSlash.

---
import { $path } from "astro-typesafe-routes";
---

<a
  href={$path("/posts/[postId]", {
    params: { postId: "1" },
    hash: "header",
    search: { filter: "recent" },
    trailingSlash: true
  })}
>
  Blog Post
</a>

Options

The Astro integration accepts some optional options.

  • outputPath - Path to the declaration file that will be generated (defaults to ./node_modules/astro-typesafe-routes.d.ts).
  • pagesDir - Directory of your Astro pages (defaults to ./src/pages).

Credit

Inspiration taken from yesmeck/remix-routes.

4.2.1

4 months ago

4.2.0

5 months ago

4.2.0-rc4

5 months ago

4.2.0-rc2

5 months ago

4.2.0-rc3

5 months ago

4.2.0-rc1

5 months ago

4.1.0-rc6

6 months ago

4.1.0-rc1

6 months ago

4.1.0-rc2

6 months ago

4.1.0-rc3

6 months ago

4.1.0-rc4

6 months ago

4.0.0-rc10

6 months ago

4.0.0-rc11

6 months ago

4.0.0-rc8

6 months ago

4.0.0-rc9

6 months ago

4.0.0-rc6

6 months ago

4.0.0-rc7

6 months ago

4.0.0-rc5

6 months ago

4.0.0

6 months ago

4.1.0

6 months ago

3.0.0-rc1

6 months ago

3.0.0-rc5

6 months ago

3.0.0-rc4

6 months ago

3.0.4

6 months ago

3.0.3

6 months ago

3.0.2

6 months ago

3.0.1

6 months ago

3.0.0-rc.2

6 months ago

4.0.0-rc4

6 months ago

4.0.0-rc2

6 months ago

4.0.0-rc3

6 months ago

4.0.0-rc1

6 months ago

2.0.13

6 months ago

2.0.11

6 months ago

2.0.12

6 months ago

2.0.9

8 months ago

2.0.10

8 months ago

2.0.8

8 months ago

3.0.0

10 months ago

2.0.7

10 months ago

2.0.6

12 months ago

2.0.5

12 months ago

1.0.0

12 months ago

1.0.0-rc1

12 months ago

1.0.0-rc2

12 months ago

2.0.3

12 months ago

2.0.2

12 months ago

2.0.4

12 months ago

2.0.1

12 months ago

2.0.0

12 months ago

0.1.9

12 months ago

0.1.8

12 months ago

0.1.7

12 months ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago