4.2.1 • Published 7 months ago

astro-typesafe-routes v4.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 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

7 months ago

4.2.0

7 months ago

4.2.0-rc4

7 months ago

4.2.0-rc2

7 months ago

4.2.0-rc3

7 months ago

4.2.0-rc1

7 months ago

4.1.0-rc6

8 months ago

4.1.0-rc1

8 months ago

4.1.0-rc2

8 months ago

4.1.0-rc3

8 months ago

4.1.0-rc4

8 months ago

4.0.0-rc10

8 months ago

4.0.0-rc11

8 months ago

4.0.0-rc8

8 months ago

4.0.0-rc9

8 months ago

4.0.0-rc6

8 months ago

4.0.0-rc7

8 months ago

4.0.0-rc5

8 months ago

4.0.0

8 months ago

4.1.0

8 months ago

3.0.0-rc1

8 months ago

3.0.0-rc5

8 months ago

3.0.0-rc4

8 months ago

3.0.4

8 months ago

3.0.3

8 months ago

3.0.2

8 months ago

3.0.1

8 months ago

3.0.0-rc.2

8 months ago

4.0.0-rc4

8 months ago

4.0.0-rc2

8 months ago

4.0.0-rc3

8 months ago

4.0.0-rc1

8 months ago

2.0.13

8 months ago

2.0.11

8 months ago

2.0.12

8 months ago

2.0.9

10 months ago

2.0.10

10 months ago

2.0.8

10 months ago

3.0.0

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

1.0.0

1 year ago

1.0.0-rc1

1 year ago

1.0.0-rc2

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.4

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year 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