4.2.1 • Published 5 months ago

astro-typesafe-routes v4.2.1

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

5 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

7 months ago

4.0.0-rc11

7 months ago

4.0.0-rc8

7 months ago

4.0.0-rc9

7 months ago

4.0.0-rc6

7 months ago

4.0.0-rc7

7 months ago

4.0.0-rc5

7 months ago

4.0.0

7 months ago

4.1.0

6 months ago

3.0.0-rc1

7 months ago

3.0.0-rc5

7 months ago

3.0.0-rc4

7 months ago

3.0.4

7 months ago

3.0.3

7 months ago

3.0.2

7 months ago

3.0.1

7 months ago

3.0.0-rc.2

7 months ago

4.0.0-rc4

7 months ago

4.0.0-rc2

7 months ago

4.0.0-rc3

7 months ago

4.0.0-rc1

7 months ago

2.0.13

7 months ago

2.0.11

7 months ago

2.0.12

7 months ago

2.0.9

8 months ago

2.0.10

8 months ago

2.0.8

8 months ago

3.0.0

11 months ago

2.0.7

11 months 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