Skip to content

Commit 1f4edd9

Browse files
authored
Merge pull request #123 from jantoniocarvajal/master
#109 Update readme and add readme_es
2 parents 8ed4322 + 53145aa commit 1f4edd9

File tree

2 files changed

+147
-27
lines changed

2 files changed

+147
-27
lines changed

14 ReactRouter/readme.md

+14-27
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ In this case we will provide a default `userName` but let the user update
66
it.
77

88

9-
We will take a startup point sample _03 State_:
9+
We will take a startup point sample _[03 State](./../03%20State)_:
1010

1111
Summary steps:
1212

1313
- Let's make first some cleanup: remove _hello.tsx_ and _nameEdit.tsx_
14-
- Let's create two components _PageA_ and _PageB_
14+
- Let's create two components _[PageA.tsx](./src/pageA.tsx)_ and _[PageB.tsx](./src/pageB.tsx)_
1515
- Let's install the dependencies to _react-router-dom_ and typescript definitions for this.
1616
- Let's define the routing.
17-
- Let's define a navigation from _PageA_ to _PageB_.
18-
- Let's define a navigation from _PageB_ to _PageA_.
17+
- Let's define a navigation from _[PageA.tsx](./src/pageA.tsx)_ to _[PageB.tsx](./src/pageB.tsx)_.
18+
- Let's define a navigation from _[PageB.tsx](./src/pageB.tsx)_ to _[PageA.tsx](./src/pageA.tsx)_.
1919

2020
## Prerequisites
2121

@@ -25,7 +25,7 @@ Install [Node.js and npm](https://nodejs.org/en/) (v6.6.0 or newer) if they are
2525
2626
## Steps to build it
2727

28-
- Copy the content from _03 State_ and execute:
28+
- Copy the content from _[03 State](./../03%20State)_ and execute:
2929

3030
```
3131
npm install
@@ -40,29 +40,22 @@ Install [Node.js and npm](https://nodejs.org/en/) (v6.6.0 or newer) if they are
4040
```jsx
4141
import * as React from "react"
4242

43-
export const PageA = () => {
44-
return (
43+
export const PageA = () =>
4544
<div>
4645
<h2>Hello from page A</h2>
4746
</div>
48-
)
49-
}
5047
```
48+
- Let's create a component called _PageB_ as _src/pageB.tsx_:
5149

5250
### ./src/pageB.tsx
5351

54-
- Let's create a component called _PageB_ as _src/pageB.tsx_:
55-
5652
```jsx
5753
import * as React from "react"
5854

59-
export const PageB = () => {
60-
return (
55+
export const PageB = () =>
6156
<div>
6257
<h2>Hello from page B</h2>
6358
</div>
64-
)
65-
}
6659
```
6760

6861
- Let's install the dependencies [`react-router-dom`](https://github.com/ReactTraining/react-router) and typescript definitions for this.
@@ -103,42 +96,36 @@ ReactDOM.render(
10396
npm start
10497
```
10598

106-
- Let's define a navigation from PageA to PageB (_src/pageA.tsx_).
99+
- Let's define a navigation from _[PageA.tsx](./src/pageA.tsx)_ to _[PageB.tsx](./src/pageB.tsx)_.
107100

108101
### ./src/pageA.tsx
109102

110103
```diff
111104
import * as React from "react"
112105
+ import { Link } from 'react-router-dom';
113106

114-
export const PageA = () => {
115-
return (
107+
export const PageA = () =>
116108
<div>
117109
<h2>Hello from page A</h2>
118110
+ <br />
119111
+ <Link to="/pageB">Navigate to Page B</Link>
120112
</div>
121-
)
122-
}
123-
124113
```
125114

126-
- Let's define a navigation from PageB to PageA (_pageA.tsx_)
115+
- Let's define a navigation from _[PageB.tsx](./src/pageB.tsx)_ to _[PageA.tsx](./src/pageA.tsx)_
116+
117+
### ./src/pageB.tsx
127118

128119
```diff
129120
import * as React from "react"
130121
+ import { Link } from 'react-router-dom';
131122

132-
export const PageB = () => {
133-
return (
123+
export const PageB = () =>
134124
<div>
135125
<h2>Hello from page B</h2>
136126
+ <br />
137127
+ <Link to="/">Navigate to Page A</Link>
138128
</div>
139-
)
140-
}
141-
142129
```
143130

144131

14 ReactRouter/readme_es.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# 14 ReactRouter
2+
3+
En este ejemplo comenzaremos a usar React-Router (navegación <acronym title="Single Page Application">SPA</acronym>).
4+
5+
En este caso proporcionaremos un `userName` por defecto pero dejaremos actualizarlo al usuario.
6+
7+
Tomaremos como punto de partida el ejemplo _[03 State](./../03%20State)_
8+
9+
Resumen de pasos:
10+
11+
- Primero vamos a hacer un poco de limpieza: eliminamos _hello.tsx_ y _nameEdit.tsx_
12+
- Vamos a crear dos componentes: _[PageA.tsx](./src/pageA.tsx)_ y _[PageB.tsx](./src/pageB.tsx)_
13+
- Vamos a instalar las dependencias a _react-router-dom_ y sus definiciones para typescript.
14+
- Vamos a definir el enrutado.
15+
- Vamos a definir la navegación de _[PageA.tsx](./src/pageA.tsx)_ a _[PageB.tsx](./src/pageB.tsx)_
16+
- Vamos a definir la navegación de _[PageB.tsx](./src/pageB.tsx)_ a _[PageA.tsx](./src/pageA.tsx)_
17+
18+
## Prerrequisitos
19+
20+
Instalar [Node.js and npm](https://nodejs.org/en/) (v6.6.0 o superior) si no las tenemos instaladas en nuestro ordenador.
21+
22+
> Verifica que estás usando al menos node v6.x.x and npm 3.x.x usando los comandos `node -v` y `npm -v` en un terminal/consola. Versiones anteriores pueden producir errores.
23+
24+
## Pasos para construirlo
25+
26+
Copia el contenido de _[03 State](./../03%20State)_ y ejecuta:
27+
28+
```
29+
npm install
30+
```
31+
32+
- Vamos a hacer algo de limpieza (eliminar los archivos _src/hello.tsx_ y _src/nameEdit.tsx_).
33+
34+
- Vamos a crear un componente llamado _PageA_ como _src/pageA.tsx_:
35+
36+
### ./src/pageA.tsx
37+
38+
```jsx
39+
import * as React from "react"
40+
41+
export const PageA = () =>
42+
<div>
43+
<h2>Hello from page A</h2>
44+
</div>
45+
```
46+
47+
- Vamos a crear un componente llamado _PageB_ como _src/pageB.tsx_:
48+
49+
### ./src/pageB.tsx
50+
51+
```jsx
52+
import * as React from "react"
53+
54+
export const PageB = () =>
55+
<div>
56+
<h2>Hello from page B</h2>
57+
</div>
58+
```
59+
60+
- Vamos a instalar las dependencias [`react-router-dom`](https://github.com/ReactTraining/react-router) y sus definiciones para typescript.
61+
62+
```bash
63+
npm install react-router-dom --save
64+
npm install @types/react-router-dom --save-dev
65+
```
66+
67+
- Vamos a definir el enrutado en _[main.tsx](./src/main.tsx)_ :
68+
69+
### ./src/main.tsx
70+
71+
```diff
72+
import * as React from 'react';
73+
import * as ReactDOM from 'react-dom';
74+
- import {App} from './app';
75+
+ import { HashRouter, Switch, Route } from 'react-router-dom';
76+
+ import {PageA} from './pageA';
77+
+ import {PageB} from './pageB';
78+
79+
ReactDOM.render(
80+
- <App />
81+
+ <HashRouter>
82+
+ <Switch>
83+
+ <Route exact={true} path="/" component={PageA} />
84+
+ <Route path="/pageB" component={PageB} />
85+
+ </Switch>
86+
+ </HashRouter>
87+
, document.getElementById('root')
88+
);
89+
```
90+
91+
- Es hora de verificar que estamos siguiendo el camino correcto:
92+
93+
```bash
94+
npm start
95+
```
96+
97+
- Vamos a definir la navegación de _[PageA.tsx](./src/pageA.tsx)_ a _[PageB.tsx](./src/pageB.tsx)_.
98+
99+
### ./src/pageA.tsx
100+
101+
```diff
102+
import * as React from "react"
103+
+ import { Link } from 'react-router-dom';
104+
105+
export const PageA = () =>
106+
<div>
107+
<h2>Hello from page A</h2>
108+
+ <br />
109+
+ <Link to="/pageB">Navigate to Page B</Link>
110+
</div>
111+
```
112+
113+
- Vamos a definir la navegación de _[PageB.tsx](./src/pageB.tsx)_ a _[PageA.tsx](./src/pageA.tsx)_
114+
115+
### ./src/pageB.tsx
116+
117+
```diff
118+
import * as React from "react"
119+
+ import { Link } from 'react-router-dom';
120+
121+
export const PageB = () =>
122+
<div>
123+
<h2>Hello from page B</h2>
124+
+ <br />
125+
+ <Link to="/">Navigate to Page A</Link>
126+
</div>
127+
```
128+
129+
- Ejecutamos la aplicación y comprobamos que la navegación funciona correctamente.
130+
131+
```bash
132+
npm start
133+
```

0 commit comments

Comments
 (0)