Skip to content

Commit 1ed589d

Browse files
ricardochlSplaktar
authored andcommitted
translate: translations for routing guides
Fixes #51
1 parent 9605917 commit 1ed589d

35 files changed

+4949
-1129
lines changed

adev-es/src/app/routing/sub-navigation-data.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -326,89 +326,89 @@ const DOCS_SUB_NAVIGATION_DATA: NavigationItem[] = [
326326
],
327327
},
328328
{
329-
label: 'Routing',
329+
label: 'Enrutamiento',
330330
status: 'updated',
331331
children: [
332332
{
333-
label: 'Overview',
333+
label: 'Visión general',
334334
path: 'guide/routing',
335335
contentPath: 'guide/routing/overview',
336336
},
337337
{
338-
label: 'Define routes',
338+
label: 'Definir rutas',
339339
path: 'guide/routing/define-routes',
340340
contentPath: 'guide/routing/define-routes',
341341
},
342342
{
343-
label: 'Show routes with Outlets',
343+
label: 'Mostrar rutas con outlets',
344344
path: 'guide/routing/show-routes-with-outlets',
345345
contentPath: 'guide/routing/show-routes-with-outlets',
346346
},
347347
{
348-
label: 'Navigate to routes',
348+
label: 'Navegar a rutas',
349349
path: 'guide/routing/navigate-to-routes',
350350
contentPath: 'guide/routing/navigate-to-routes',
351351
},
352352
{
353-
label: 'Read route state',
353+
label: 'Leer estado de ruta',
354354
path: 'guide/routing/read-route-state',
355355
contentPath: 'guide/routing/read-route-state',
356356
},
357357
{
358-
label: 'Redirecting routes',
358+
label: 'Redirigir rutas',
359359
path: 'guide/routing/redirecting-routes',
360360
contentPath: 'guide/routing/redirecting-routes',
361361
},
362362
{
363-
label: 'Control route access with guards',
363+
label: 'Controlar acceso a rutas con guards',
364364
path: 'guide/routing/route-guards',
365365
contentPath: 'guide/routing/route-guards',
366366
},
367367
{
368-
label: 'Route data resolvers',
368+
label: 'Resolvers de datos de ruta',
369369
path: 'guide/routing/data-resolvers',
370370
contentPath: 'guide/routing/data-resolvers',
371371
},
372372
{
373-
label: 'Lifecycle and events',
373+
label: 'Ciclo de vida y eventos',
374374
path: 'guide/routing/lifecycle-and-events',
375375
contentPath: 'guide/routing/lifecycle-and-events',
376376
},
377377
{
378-
label: 'Testing routing and navigation',
378+
label: 'Pruebas de routing y navegación',
379379
path: 'guide/routing/testing',
380380
contentPath: 'guide/routing/testing',
381381
status: 'new',
382382
},
383383
{
384-
label: 'Other routing tasks',
384+
label: 'Otras tareas de routing',
385385
path: 'guide/routing/common-router-tasks',
386386
contentPath: 'guide/routing/common-router-tasks',
387387
},
388388
{
389-
label: 'Creating custom route matches',
389+
label: 'Creando coincidencias de ruta personalizadas',
390390
path: 'guide/routing/routing-with-urlmatcher',
391391
contentPath: 'guide/routing/routing-with-urlmatcher',
392392
},
393393
{
394-
label: 'Rendering strategies',
394+
label: 'Estrategias de renderizado',
395395
path: 'guide/routing/rendering-strategies',
396396
contentPath: 'guide/routing/rendering-strategies',
397397
status: 'new',
398398
},
399399
{
400-
label: 'Customizing route behavior',
400+
label: 'Personalizar comportamiento de ruta',
401401
path: 'guide/routing/customizing-route-behavior',
402402
contentPath: 'guide/routing/customizing-route-behavior',
403403
status: 'new',
404404
},
405405
{
406-
label: 'Router reference',
406+
label: 'Referencia del Router',
407407
path: 'guide/routing/router-reference',
408408
contentPath: 'guide/routing/router-reference',
409409
},
410410
{
411-
label: 'Route transition animations',
411+
label: 'Animaciones de transición de ruta',
412412
path: 'guide/routing/route-transition-animations',
413413
contentPath: 'guide/routing/route-transition-animations',
414414
},
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Other common Routing Tasks
2+
3+
This guide covers some other common tasks associated with using Angular router in your application.
4+
5+
## Getting route information
6+
7+
Often, as a user navigates your application, you want to pass information from one component to another.
8+
For example, consider an application that displays a shopping list of grocery items.
9+
Each item in the list has a unique `id`.
10+
To edit an item, users click an Edit button, which opens an `EditGroceryItem` component.
11+
You want that component to retrieve the `id` for the grocery item so it can display the right information to the user.
12+
13+
Use a route to pass this type of information to your application components.
14+
To do so, you use the [`withComponentInputBinding`](api/router/withComponentInputBinding) feature with `provideRouter` or the `bindToComponentInputs` option of `RouterModule.forRoot`.
15+
16+
To get information from a route:
17+
18+
<docs-workflow>
19+
20+
<docs-step title="Add `withComponentInputBinding`">
21+
22+
Add the `withComponentInputBinding` feature to the `provideRouter` method.
23+
24+
```ts
25+
providers: [
26+
provideRouter(appRoutes, withComponentInputBinding()),
27+
]
28+
```
29+
30+
</docs-step>
31+
32+
<docs-step title="Add an `input` to the component">
33+
34+
Update the component to have an `input()` property matching the name of the parameter.
35+
36+
```ts
37+
id = input.required<string>()
38+
hero = computed(() => this.service.getHero(id));
39+
```
40+
41+
</docs-step>
42+
<docs-step title="Optional: Use a default value">
43+
The router assigns values to all inputs based on the current route when `withComponentInputBinding` is enabled.
44+
The router assigns `undefined` if no route data matches the input key, such as when an optional query parameter is missing.
45+
You should include `undefined` in the `input`'s type when there's a possibility that an input might not be matched by the route.
46+
47+
Provide a default value by either using the `transform` option on the input or managing a local state with a `linkedSignal`.
48+
49+
```ts
50+
id = input.required({
51+
transform: (maybeUndefined: string | undefined) => maybeUndefined ?? '0',
52+
});
53+
// or
54+
id = input<string|undefined>();
55+
internalId = linkedSignal(() => this.id() ?? getDefaultId());
56+
```
57+
58+
</docs-step>
59+
</docs-workflow>
60+
61+
NOTE: You can bind all route data with key, value pairs to component inputs: static or resolved route data, path parameters, matrix parameters, and query parameters.
62+
If you want to use the parent components route info you will need to set the router `paramsInheritanceStrategy` option:
63+
`withRouterConfig({paramsInheritanceStrategy: 'always'})`
64+
65+
## Displaying a 404 page
66+
67+
To display a 404 page, set up a [wildcard route](guide/routing/common-router-tasks#setting-up-wildcard-routes) with the `component` property set to the component you'd like to use for your 404 page as follows:
68+
69+
```ts
70+
const routes: Routes = [
71+
{ path: 'first-component', component: FirstComponent },
72+
{ path: 'second-component', component: SecondComponent },
73+
{ path: '**', component: PageNotFoundComponent }, // Wildcard route for a 404 page
74+
];
75+
```
76+
77+
The last route with the `path` of `**` is a wildcard route.
78+
The router selects this route if the requested URL doesn't match any of the paths earlier in the list and sends the user to the `PageNotFoundComponent`.
79+
80+
## Link parameters array
81+
82+
A link parameters array holds the following ingredients for router navigation:
83+
84+
- The path of the route to the destination component
85+
- Required and optional route parameters that go into the route URL
86+
87+
Bind the `RouterLink` directive to such an array like this:
88+
89+
```angular-html
90+
<a [routerLink]="['/heroes']">Heroes</a>
91+
```
92+
93+
The following is a two-element array when specifying a route parameter:
94+
95+
```angular-html
96+
<a [routerLink]="['/hero', hero.id]">
97+
<span class="badge">{{ hero.id }}</span>{{ hero.name }}
98+
</a>
99+
```
100+
101+
Provide optional route parameters in an object, as in `{ foo: 'foo' }`:
102+
103+
```angular-html
104+
<a [routerLink]="['/crisis-center', { foo: 'foo' }]">Crisis Center</a>
105+
```
106+
107+
These three examples cover the needs of an application with one level of routing.
108+
However, with a child router, such as in the crisis center, you create new link array possibilities.
109+
110+
The following minimal `RouterLink` example builds upon a specified default child route for the crisis center.
111+
112+
```angular-html
113+
<a [routerLink]="['/crisis-center']">Crisis Center</a>
114+
```
115+
116+
Review the following:
117+
118+
- The first item in the array identifies the parent route \(`/crisis-center`\)
119+
- There are no parameters for this parent route
120+
- There is no default for the child route so you need to pick one
121+
- You're navigating to the `CrisisListComponent`, whose route path is `/`, but you don't need to explicitly add the slash
122+
123+
Consider the following router link that navigates from the root of the application down to the Dragon Crisis:
124+
125+
```angular-html
126+
<a [routerLink]="['/crisis-center', 1]">Dragon Crisis</a>
127+
```
128+
129+
- The first item in the array identifies the parent route \(`/crisis-center`\)
130+
- There are no parameters for this parent route
131+
- The second item identifies the child route details about a particular crisis \(`/:id`\)
132+
- The details child route requires an `id` route parameter
133+
- You added the `id` of the Dragon Crisis as the second item in the array \(`1`\)
134+
- The resulting path is `/crisis-center/1`
135+
136+
You could also redefine the `AppComponent` template with Crisis Center routes exclusively:
137+
138+
```angular-ts
139+
@Component({
140+
template: `
141+
<h1 class="title">Angular Router</h1>
142+
<nav>
143+
<a [routerLink]="['/crisis-center']">Crisis Center</a>
144+
<a [routerLink]="['/crisis-center/1', { foo: 'foo' }]">Dragon Crisis</a>
145+
<a [routerLink]="['/crisis-center/2']">Shark Crisis</a>
146+
</nav>
147+
<router-outlet />
148+
`
149+
})
150+
export class AppComponent {}
151+
```
152+
153+
In summary, you can write applications with one, two or more levels of routing.
154+
The link parameters array affords the flexibility to represent any routing depth and any legal sequence of route paths, \(required\) router parameters, and \(optional\) route parameter objects.
155+
156+
## `LocationStrategy` and browser URL styles
157+
158+
When the router navigates to a new component view, it updates the browser's location and history with a URL for that view.
159+
160+
Modern HTML5 browsers support [history.pushState](https://developer.mozilla.org/docs/Web/API/History_API/Working_with_the_History_API#adding_and_modifying_history_entries 'HTML5 browser history push-state'), a technique that changes a browser's location and history without triggering a server page request.
161+
The router can compose a "natural" URL that is indistinguishable from one that would otherwise require a page load.
162+
163+
Here's the Crisis Center URL in this "HTML5 pushState" style:
164+
165+
```text
166+
localhost:3002/crisis-center
167+
```
168+
169+
Older browsers send page requests to the server when the location URL changes unless the change occurs after a "#" \(called the "hash"\).
170+
Routers can take advantage of this exception by composing in-application route URLs with hashes.
171+
Here's a "hash URL" that routes to the Crisis Center.
172+
173+
```text
174+
localhost:3002/src/#/crisis-center
175+
```
176+
177+
The router supports both styles with two `LocationStrategy` providers:
178+
179+
| Providers | Details |
180+
| :--------------------- | :----------------------------------- |
181+
| `PathLocationStrategy` | The default "HTML5 pushState" style. |
182+
| `HashLocationStrategy` | The "hash URL" style. |
183+
184+
The `RouterModule.forRoot()` function sets the `LocationStrategy` to the `PathLocationStrategy`, which makes it the default strategy.
185+
You also have the option of switching to the `HashLocationStrategy` with an override during the bootstrapping process.
186+
187+
HELPFUL: For more information on providers and the bootstrap process, see [Dependency Injection](guide/di/dependency-injection-providers).

0 commit comments

Comments
 (0)