You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/architecture-concepts.md
+51
Original file line number
Diff line number
Diff line change
@@ -92,3 +92,54 @@ author:
92
92
93
93
Lorem ipsum dolor sit amet, etc.
94
94
```
95
+
96
+
97
+
## Automatic Routing
98
+
99
+
>info This covers an intermediate topic which is not required for basic usage, but is useful if you want to use the framework to design custom Blade templates.
100
+
101
+
### High-level overview
102
+
103
+
If you've ever worked in a MVC framework, you are probably familiar with the concept of routing. And you are probably also familiar with how boring and tedious it can be. Hyde takes the pain out of routing through the Hyde Autodiscovery process.
104
+
105
+
Internally, when booting the Hyde application, Hyde will automatically discover all of the content files in the source directory and create a routing index for them. This index works as a two-way link between source files and compiled files.
106
+
107
+
Don't worry if this sounds complex, as the key takeaway is that the index is created and maintained automatically. There is currently no way to manually add or remove files from the index. Making it function more like a source map than a proper router. Nevertheless, the routing system provides several helpers that you can optionally use in your Blade views to automatically resolve relative links and other useful features.
108
+
109
+
### Accessing routes
110
+
111
+
Each route in your site is represented by a Route object. It's very easy to get a Route object instance from the Router's index. There are a few ways to do this, but most commonly you'll use the Route facade's `get()` method where you provide a route key, and it will return the Route object. The route key is generally `<output-directory/slug>`. Here are some examples:
112
+
113
+
```php
114
+
// Source file: _pages/index.md/index.blade.php
115
+
// Compiled file: _site/index.html
116
+
Route::get('index')
117
+
118
+
// Source file: _posts/my-post.md
119
+
// Compiled file: _site/posts/my-post.html
120
+
Route::get('posts.my-post')
121
+
122
+
// Source file: _docs/readme.md
123
+
// Compiled file: _site/docs/readme.html
124
+
Route::get('docs.readme')
125
+
```
126
+
127
+
### Using the `x-link` component
128
+
129
+
When designing Blade layouts it can be useful to use the `x-link` component to automatically resolve relative links.
130
+
131
+
You can of course, use it just like a normal anchor tag like so:
132
+
```blade
133
+
<x-link href="index.html">Home</x-link>
134
+
```
135
+
136
+
But where it really shines is when you supply a route. This will then resolve the proper relative link, and format it to use pretty URLs if your site is configured to use them.
137
+
138
+
```blade
139
+
<x-link href="Route::get('index')">Home</x-link>
140
+
```
141
+
142
+
You can of course, also supply extra attributes like classes:
0 commit comments