Skip to content

Commit fe3e183

Browse files
authored
Merge pull request #35 from nckrtl/patch-1
Update README.md to improve integration
2 parents ce8a2e5 + 410d139 commit fe3e183

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

README.md

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,6 @@ export default defineConfig({
4040
});
4141
```
4242

43-
For convenience, you may also wish to register aliases for importing the generated files into your application:
44-
45-
```ts
46-
export default defineConfig({
47-
// ...
48-
resolve: {
49-
alias: {
50-
"@actions/": "./resources/js/actions",
51-
"@routes/": "./resources/js/routes",
52-
},
53-
},
54-
});
55-
```
56-
5743
## Generating TypeScript Definitions
5844

5945
The `wayfinder:generate` command can be used to generate TypeScript definitions for your routes and controller methods:
@@ -82,15 +68,15 @@ You can safely `.gitignore` the `wayfinder`, `actions`, and `routes` directories
8268
Wayfinder functions return an object that contains the resolved URL and default HTTP method:
8369

8470
```ts
85-
import { show } from "@actions/App/Http/Controllers/PostController";
71+
import { show } from "@/actions/App/Http/Controllers/PostController";
8672

8773
show(1); // { url: "/posts/1", method: "get" }
8874
```
8975

9076
If you just need the URL, or would like to choose a method from the HTTP methods defined on the server, you can invoke additional methods on the Wayfinder generated function:
9177

9278
```ts
93-
import { show } from "@actions/App/Http/Controllers/PostController";
79+
import { show } from "@/actions/App/Http/Controllers/PostController";
9480

9581
show.url(1); // "/posts/1"
9682
show.head(1); // { url: "/posts/1", method: "head" }
@@ -99,7 +85,7 @@ show.head(1); // { url: "/posts/1", method: "head" }
9985
Wayfinder functions accept a variety of shapes for their arguments:
10086

10187
```ts
102-
import { show, update } from "@actions/App/Http/Controllers/PostController";
88+
import { show, update } from "@/actions/App/Http/Controllers/PostController";
10389

10490
// Single parameter action...
10591
show(1);
@@ -117,7 +103,7 @@ update({ post: { id: 1 }, author: { id: 2 } });
117103
If you've specified a key for the parameter binding, Wayfinder will detect this and allow you to pass the value in as a property on an object:
118104

119105
```ts
120-
import { show } from "@actions/App/Http/Controllers/PostController";
106+
import { show } from "@/actions/App/Http/Controllers/PostController";
121107

122108
// Route is /posts/{post:slug}...
123109
show("my-new-post");
@@ -129,7 +115,7 @@ show({ slug: "my-new-post" });
129115
If your controller is an invokable controller, you may simply invoke the imported Wayfinder function directly:
130116

131117
```ts
132-
import StorePostController from "@actions/App/Http/Controllers/StorePostController";
118+
import StorePostController from "@/actions/App/Http/Controllers/StorePostController";
133119

134120
StorePostController();
135121
```
@@ -139,7 +125,7 @@ StorePostController();
139125
You may also import the Wayfinder generated controller definition and invoke its individual methods on the imported object:
140126

141127
```ts
142-
import PostController from "@actions/App/Http/Controllers/PostController";
128+
import PostController from "@/actions/App/Http/Controllers/PostController";
143129

144130
PostController.show(1);
145131
```
@@ -152,7 +138,7 @@ PostController.show(1);
152138
Wayfinder can also generate methods for your application's named routes as well:
153139

154140
```ts
155-
import { show } from "@routes/post";
141+
import { show } from "@/routes/post";
156142

157143
// Named route is `post.show`...
158144
show(1); // { url: "/posts/1", method: "get" }
@@ -169,7 +155,7 @@ php artisan wayfinder:generate --with-form
169155
Then, you can use the `.form` variant to generate `<form>` object attributes automatically:
170156

171157
```tsx
172-
import { store, update } from "@actions/App/Http/Controllers/PostController";
158+
import { store, update } from "@/actions/App/Http/Controllers/PostController";
173159

174160
const Page = () => (
175161
<form {...store.form()}>
@@ -189,7 +175,7 @@ const Page = () => (
189175
If your form action supports multiple methods and would like to specify a method, you can invoke additional methods on the `form`:
190176

191177
```tsx
192-
import { store, update } from "@actions/App/Http/Controllers/PostController";
178+
import { store, update } from "@/actions/App/Http/Controllers/PostController";
193179

194180
const Page = () => (
195181
<form {...update.form.put(1)}>
@@ -204,7 +190,7 @@ const Page = () => (
204190
All Wayfinder methods accept an optional, final `options` argument to which you may pass a `query` object. This object can be used to append query parameters onto the resulting URL:
205191

206192
```ts
207-
import { show } from "@actions/App/Http/Controllers/PostController";
193+
import { show } from "@/actions/App/Http/Controllers/PostController";
208194

209195
const options = {
210196
query: {
@@ -222,7 +208,7 @@ show.form.head(1, options); // { action: "/posts/1?page=1&sort_by=name&_method=H
222208
You can also merge with the URL's existing parameters by passing a `mergeQuery` object instead:
223209

224210
```ts
225-
import { show } from "@actions/App/Http/Controllers/PostController";
211+
import { show } from "@/actions/App/Http/Controllers/PostController";
226212

227213
// window.location.search = "?page=1&sort_by=category&q=shirt"
228214

@@ -239,7 +225,7 @@ show.url(1, options); // "/posts/1?page=2&sort_by=name&q=shirt"
239225
If you would like to remove a parameter from the resulting URL, define the value as `null` or `undefined`:
240226

241227
```ts
242-
import { show } from "@actions/App/Http/Controllers/PostController";
228+
import { show } from "@/actions/App/Http/Controllers/PostController";
243229

244230
// window.location.search = "?page=1&sort_by=category&q=shirt"
245231

@@ -261,7 +247,7 @@ When using [Inertia](https://inertiajs.com), you can pass the result of a Wayfin
261247

262248
```ts
263249
import { useForm } from "@inertiajs/react";
264-
import { store } from "@actions/App/Http/Controllers/PostController";
250+
import { store } from "@/actions/App/Http/Controllers/PostController";
265251

266252
const form = useForm({
267253
name: "My Big Post",
@@ -276,7 +262,7 @@ You may also use Wayfinder in conjunction with Inertia's `Link` component:
276262

277263
```tsx
278264
import { Link } from "@inertiajs/react";
279-
import { show } from "@actions/App/Http/Controllers/PostController";
265+
import { show } from "@/actions/App/Http/Controllers/PostController";
280266

281267
const Nav = () => <Link href={show(1)}>Show me the first post</Link>;
282268
```

0 commit comments

Comments
 (0)