@arielgonzaguer/michi-router 1.0.4 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +275 -277
  2. package/package.json +40 -40
package/README.md CHANGED
@@ -1,277 +1,275 @@
1
- # Michi Router
2
-
3
- ![npm version](https://img.shields.io/npm/v/@arielgonzaguer/michi-router)
4
- ![bundle size](https://img.shields.io/bundlephobia/minzip/@arielgonzaguer/michi-router)
5
- ![license](https://img.shields.io/npm/l/@arielgonzaguer/michi-router)
6
-
7
- El router minimalista y simple para React.
8
- El objetivo principal de esta herramienta es proporcionar la funcionalidad básica de enrutamiento.
9
-
10
- ## Características
11
-
12
- - Es ideal para proyectos pequeños o que solo necesitan una funcionalidad básica de enrutamiento.
13
- - No requiere de ninguna configuración adicional.
14
- - No requiere de ninguna dependencia externa.
15
- - Creado con TypeScript.
16
- - Ultra ligero. Menos de 20kb (más ligero y básico que otras librerías).
17
-
18
- ## Compatibilidad
19
-
20
- - React 16.8+.
21
- - Funciona con proyectos creados con Create React App, Vite, Next.js, etc.
22
- - Totalmente tipado con TypeScript.
23
-
24
- ## Installation
25
-
26
- ```bash
27
- npm install @arielgonzaguer/michi-router
28
- ```
29
-
30
- ## Uso básico
31
-
32
- ```jsx
33
- // src/App.jsx //
34
- import { RouterProvider, Link } from "@arielgonzaguer/michi-router";
35
-
36
- // puede crear rutas en un archivo separado o en el mismo archivo
37
- const routes = [
38
- { path: "/", component: <Home /> },
39
- { path: "/about", component: <About /> },
40
- ];
41
-
42
- function App() {
43
- return (
44
- <RouterProvider routes={routes}>
45
- {/* Esto se muestra si no se encuentra una ruta */}
46
- <div>404: Page not found</div>
47
- </RouterProvider>
48
- );
49
- }
50
- ```
51
-
52
- ### Usando Link
53
-
54
- #### Usando el componente Link solo con prop to
55
- ```jsx
56
- function NavigationComponent() {
57
- return (
58
- <nav>
59
- <Link to="/">Home</Link>
60
- <Link to="/about">About</Link>
61
- </nav>
62
- );
63
- }
64
- ```
65
-
66
- #### Usando el componente Link con todas las props
67
- ```jsx
68
- <Link
69
- to="/contact"
70
- className="nav-link"
71
- target="_blank"
72
- rel="noopener noreferrer"
73
- aria-label="Contacto"
74
- >
75
- Contacto
76
- </Link>
77
- ```
78
-
79
-
80
-
81
- ### Navegación programática (Hook useNavigate)
82
-
83
- ```jsx
84
- import { useNavigate } from "@arielgonzaguer/michi-router";
85
-
86
- function NavigateButton() {
87
- const navigate = useNavigate();
88
- return <button onClick={() => navigate("/about")}>Ir a About</button>;
89
- }
90
- ```
91
-
92
- ### Organización de rutas en archivos separados
93
-
94
- Para aplicaciones más grandes, puedes organizar tus rutas en archivos separados:
95
-
96
- ```jsx
97
- // routes.js
98
- import Home from "./pages/Home";
99
- import About from "./pages/About";
100
- import Products from "./pages/Products";
101
- import NotFound from "./pages/NotFound";
102
-
103
- export const routes = [
104
- { path: "/", component: <Home /> },
105
- { path: "/about", component: <About /> },
106
- { path: "/products", component: <Products /> },
107
- ];
108
-
109
- export const notFoundPage = <NotFound />;
110
- ```
111
-
112
- ```jsx
113
- // App.jsx
114
- import { RouterProvider } from "@arielgonzaguer/michi-router";
115
- import { routes, notFoundPage } from "./routes";
116
-
117
- function App() {
118
- return <RouterProvider routes={routes}>{notFoundPage}</RouterProvider>;
119
- }
120
- ```
121
-
122
- ### Integración con sistemas de autenticación
123
-
124
- ```jsx
125
- import { RouterProvider } from "@arielgonzaguer/michi-router";
126
- import { useAuth } from "./auth-context";
127
-
128
- function App() {
129
- const { isAuthenticated } = useAuth();
130
-
131
- // Definimos rutas condicionalmente basadas en autenticación
132
- const routes = [
133
- { path: "/", component: <Home /> },
134
- { path: "/login", component: <Login /> },
135
- // Solo agregamos estas rutas si el usuario está autenticado
136
- ...(isAuthenticated
137
- ? [
138
- { path: "/profile", component: <Profile /> },
139
- { path: "/admin", component: <Admin /> },
140
- ]
141
- : []),
142
- ];
143
-
144
- return (
145
- <RouterProvider routes={routes}>
146
- <div>404: Page not found</div>
147
- </RouterProvider>
148
- );
149
- }
150
- ```
151
-
152
- ### Usando un Layout General
153
-
154
- Puedes aplicar un layout común a todas tus rutas:
155
-
156
- ```jsx
157
- import { RouterProvider } from "@arielgonzaguer/michi-router";
158
- import MainLayout from "./layouts/MainLayout";
159
-
160
- const routes = [
161
- { path: "/", component: <Home /> },
162
- { path: "/about", component: <About /> },
163
- ];
164
-
165
- function App() {
166
- return (
167
- <RouterProvider routes={routes} layout={MainLayout}>
168
- <div>404: Page not found</div>
169
- </RouterProvider>
170
- );
171
- }
172
-
173
- // Ejemplo de un componente Layout
174
- function MainLayout({ children }) {
175
- return (
176
- <div className="layout">
177
- <header>
178
- <nav>
179
- <Link to="/">Home</Link>
180
- <Link to="/about">About</Link>
181
- </nav>
182
- </header>
183
- <main>{children}</main>
184
- <footer>Michi-router 😸</footer>
185
- </div>
186
- );
187
- }
188
- ```
189
-
190
- ## API
191
-
192
- ### `<RouterProvider>`
193
-
194
- Componente principal para el enrutamiento.
195
-
196
- **Props:**
197
-
198
- - `routes`: Array de objetos con `path` y `component`.
199
- - `children`: Elemento a mostrar cuando no hay ruta coincidente.
200
- - `layout`: Componente opcional que funciona como layout general para todas las rutas.
201
-
202
- ### `<Link>`
203
-
204
- Componente para navegación declarativa.
205
-
206
- **Props:**
207
-
208
- - `to`: Ruta destino.
209
- - `children`: Contenido del enlace.
210
- - `className`: Clases CSS opcionales.
211
- - `...rest`: Cualquier otra prop válida para elementos `<a>` de HTML.
212
-
213
- ### `useNavigate()`
214
-
215
- Hook para navegación programática.
216
-
217
- **Retorna:**
218
-
219
- - Función navigate que acepta la ruta como parámetro.
220
-
221
- ## Próximas características
222
-
223
- - [ ] Soporte para rutas anidadas.
224
-
225
- ```jsx
226
- const routes = [
227
- {
228
- path: "/dashboard",
229
- component: <Dashboard />,
230
- children: [
231
- { path: "/users", component: <Users /> },
232
- { path: "/settings", component: <Settings /> },
233
- ],
234
- },
235
- ];
236
- ```
237
-
238
- - [ ] Transiciones entre rutas.
239
-
240
- ```jsx
241
- <RouterProvider routes={routes} transitions={true} transitionDuration={300}>
242
- <NotFound />
243
- </RouterProvider>
244
- ```
245
-
246
- ## Solución de problemas comunes
247
-
248
- ### El componente no se renderiza después de navegar
249
-
250
- Asegúrate de que la ruta en el array `routes` coincida exactamente con la URL, incluyendo barras diagonales.
251
-
252
- ### Errores con TypeScript
253
-
254
- Si estás usando TypeScript, asegúrate de importar los tipos correctamente:
255
-
256
- ```typescript
257
- import {
258
- RouterProvider,
259
- Link,
260
- useNavigate,
261
- } from "@arielgonzaguer/michi-router";
262
- import type { RouterProviderProps } from "@arielgonzaguer/michi-router";
263
- ```
264
-
265
- ## Contribuir
266
-
267
- Las contribuciones son bienvenidas. Por favor, sigue estos pasos:
268
-
269
- 1. Fork el repositorio.
270
- 2. Crea una rama para tu feature (`git checkout -b feature/amazing-feature`).
271
- 3. Haz commit de tus cambios (`git commit -m 'Add some amazing feature'`).
272
- 4. Push a la rama (`git push origin feature/amazing-feature`).
273
- 5. Abre un Pull Request.
274
-
275
- ## Licencia
276
-
277
- MIT
1
+ # Michi Router
2
+
3
+ ![npm version](https://img.shields.io/npm/v/@arielgonzaguer/michi-router)
4
+ ![bundle size](https://img.shields.io/bundlephobia/minzip/@arielgonzaguer/michi-router)
5
+ ![license](https://img.shields.io/npm/l/@arielgonzaguer/michi-router)
6
+
7
+
8
+ # ¡IMPORTANTE!
9
+
10
+ Las versiones 1.1.x publicadas antes del 18/marzo/2025 están rotas, contienen errores y han sido eliminadas.
11
+ La versión estable es la 1.2.0.
12
+ Si tienes alguna de estas versiones instaladas (1.1.x), actualízala a la versión 1.2.0 ejecutando el siguiente comando:
13
+ ```bash
14
+ npm install @arielgonzaguer/michi-router@latest
15
+ ```
16
+
17
+ O:
18
+ ```bash
19
+ npm install @arielgonzaguer/michi-router@1.2.0
20
+ ```
21
+
22
+ Gracias por tu comprensión 😸
23
+
24
+ El router minimalista y simple para React.
25
+ El objetivo principal de esta herramienta es proporcionar la funcionalidad básica de enrutamiento.
26
+
27
+
28
+ ## Características
29
+
30
+ - Es ideal para proyectos pequeños o que solo necesitan una funcionalidad básica de enrutamiento.
31
+ - No requiere de ninguna configuración adicional.
32
+ - No requiere de ninguna dependencia externa.
33
+ - Creado con TypeScript.
34
+ - Ultra ligero.
35
+
36
+
37
+ ## Compatibilidad
38
+
39
+ - React 16.8+.
40
+ - Funciona con proyectos creados con Vite, Next.js, etc.
41
+ - Totalmente tipado con TypeScript.
42
+
43
+ ## Instalación
44
+
45
+ ```bash
46
+ npm install @arielgonzaguer/michi-router
47
+ ```
48
+
49
+ ## Uso básico
50
+
51
+ ```jsx
52
+ // src/App.jsx //
53
+ import { RouterProvider} from "@arielgonzaguer/michi-router";
54
+
55
+ // puede crear rutas en un archivo separado o en el mismo archivo
56
+ const routes = [
57
+ { path: "/", component: <Home /> },
58
+ { path: "/about", component: <About /> },
59
+ ];
60
+
61
+ function App() {
62
+ return (
63
+ <RouterProvider routes={routes}>
64
+ {/* Esto se muestra si no se encuentra una ruta */}
65
+ <div>404: Page not found</div>
66
+ </RouterProvider>
67
+ );
68
+ }
69
+ ```
70
+
71
+ ### Usando Link
72
+
73
+ #### Usando el componente Link solo con prop to
74
+ ```jsx
75
+ import { Link} from "@arielgonzaguer/michi-router";
76
+
77
+ function NavigationComponent() {
78
+ return (
79
+ <nav>
80
+ <Link to="/">Home</Link>
81
+ <Link to="/about">About</Link>
82
+ </nav>
83
+ );
84
+ }
85
+ ```
86
+
87
+ #### Usando el componente Link con todas las props
88
+ ```jsx
89
+ import { Link} from "@arielgonzaguer/michi-router";
90
+
91
+ <Link
92
+ to="/contact"
93
+ className="nav-link"
94
+ target="_blank"
95
+ rel="noopener noreferrer"
96
+ aria-label="Contacto"
97
+ >
98
+ Contacto
99
+ </Link>
100
+ ```
101
+
102
+
103
+
104
+ ### Navegación programática (Hook useNavigate)
105
+
106
+ ```jsx
107
+ import { useNavigate } from "@arielgonzaguer/michi-router";
108
+
109
+ function NavigateButton() {
110
+ const navigate = useNavigate();
111
+ return <button onClick={() => navigate("/about")}>Ir a About</button>;
112
+ }
113
+ ```
114
+
115
+ ### Organización de rutas en archivos separados
116
+
117
+ Para aplicaciones más grandes, puedes organizar tus rutas en archivos separados:
118
+
119
+ ```jsx
120
+ // routes.js
121
+ import Home from "./pages/Home";
122
+ import About from "./pages/About";
123
+ import Products from "./pages/Products";
124
+ import NotFound from "./pages/NotFound";
125
+
126
+ export const routes = [
127
+ { path: "/", component: <Home /> },
128
+ { path: "/about", component: <About /> },
129
+ { path: "/products", component: <Products /> },
130
+ ];
131
+
132
+ export const notFoundPage = <NotFound />;
133
+ ```
134
+
135
+ ```jsx
136
+ // App.jsx
137
+ import { RouterProvider } from "@arielgonzaguer/michi-router";
138
+ import { routes, notFoundPage } from "./routes";
139
+
140
+ function App() {
141
+ return <RouterProvider routes={routes}>{notFoundPage}</RouterProvider>;
142
+ }
143
+ ```
144
+
145
+ ### Integración con sistemas de autenticación
146
+
147
+ ```jsx
148
+ import { RouterProvider } from "@arielgonzaguer/michi-router";
149
+ import { useAuth } from "./auth-context";
150
+
151
+ function App() {
152
+ const { isAuthenticated } = useAuth();
153
+
154
+ // Definimos rutas condicionalmente basadas en autenticación
155
+ const routes = [
156
+ { path: "/", component: <Home /> },
157
+ { path: "/login", component: <Login /> },
158
+ // Solo agregamos estas rutas si el usuario está autenticado
159
+ ...(isAuthenticated
160
+ ? [
161
+ { path: "/profile", component: <Profile /> },
162
+ { path: "/admin", component: <Admin /> },
163
+ ]
164
+ : []),
165
+ ];
166
+
167
+ return (
168
+ <RouterProvider routes={routes}>
169
+ <div>404: Page not found</div>
170
+ </RouterProvider>
171
+ );
172
+ }
173
+ ```
174
+
175
+ ### Usando un Layout General
176
+
177
+ Puedes aplicar un layout común a todas tus rutas:
178
+
179
+ ```jsx
180
+ import { RouterProvider } from "@arielgonzaguer/michi-router";
181
+ import MainLayout from "./layouts/MainLayout";
182
+
183
+ const routes = [
184
+ { path: "/", component: <Home /> },
185
+ { path: "/about", component: <About /> },
186
+ ];
187
+
188
+ function App() {
189
+ return (
190
+ <RouterProvider routes={routes} layout={MainLayout}>
191
+ <div>404: Page not found</div>
192
+ </RouterProvider>
193
+ );
194
+ }
195
+
196
+ // Ejemplo de un componente Layout
197
+ function MainLayout({ children }) {
198
+ return (
199
+ <div className="layout">
200
+ <header>
201
+ <nav>
202
+ <Link to="/">Home</Link>
203
+ <Link to="/about">About</Link>
204
+ </nav>
205
+ </header>
206
+ <main>{children}</main>
207
+ <footer>Michi-router 😸</footer>
208
+ </div>
209
+ );
210
+ }
211
+ ```
212
+
213
+ ## API
214
+
215
+ ### `<RouterProvider>`
216
+
217
+ Componente principal para el enrutamiento.
218
+
219
+ **Props:**
220
+
221
+ - `routes`: Array de objetos con `path` y `component`.
222
+ - `children`: Elemento a mostrar cuando no hay ruta coincidente.
223
+ - `layout`: Componente opcional que funciona como layout general para todas las rutas.
224
+
225
+ ### `<Link>`
226
+
227
+ Componente para navegación declarativa.
228
+
229
+ **Props:**
230
+
231
+ - `to`: Ruta destino.
232
+ - `children`: Contenido del enlace.
233
+ - `className`: Clases CSS opcionales.
234
+ - `...rest`: Cualquier otra prop válida para elementos `<a>` de HTML.
235
+
236
+ ### `useNavigate()`
237
+
238
+ Hook para navegación programática.
239
+
240
+ **Retorna:**
241
+
242
+ - Función navigate que acepta la ruta como parámetro.
243
+
244
+ ## Solución de problemas comunes
245
+
246
+ ### El componente no se renderiza después de navegar
247
+
248
+ Asegúrate de que la ruta en el array `routes` coincida exactamente con la URL, incluyendo barras diagonales.
249
+
250
+ ### Errores con TypeScript
251
+
252
+ Si estás usando TypeScript, asegúrate de importar los tipos correctamente:
253
+
254
+ ```typescript
255
+ import {
256
+ RouterProvider,
257
+ Link,
258
+ useNavigate,
259
+ } from "@arielgonzaguer/michi-router";
260
+ import type { RouterProviderProps } from "@arielgonzaguer/michi-router";
261
+ ```
262
+
263
+ ## Contribuir
264
+
265
+ Las contribuciones son bienvenidas. Por favor, sigue estos pasos:
266
+
267
+ 1. Fork el repositorio.
268
+ 2. Crea una rama para tu feature (`git checkout -b feature/amazing-feature`).
269
+ 3. Haz commit de tus cambios (`git commit -m 'Add some amazing feature'`).
270
+ 4. Push a la rama (`git push origin feature/amazing-feature`).
271
+ 5. Abre un Pull Request.
272
+
273
+ ## Licencia
274
+
275
+ MIT
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "@arielgonzaguer/michi-router",
3
- "private": false,
4
- "version": "1.0.4",
5
- "description": "El router minimalista y simple para React.\nEl objetivo principal de esta herramienta es proporcionar la funcionalidad básica de enrutamiento.",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "scripts": {
12
- "build": "tsc",
13
- "prepare": "npm run build",
14
- "clean": "rimraf dist",
15
- "prebuild": "npm run clean",
16
- "prepublishOnly": "npm run build"
17
- },
18
- "keywords": [
19
- "react",
20
- "router",
21
- "typescript",
22
- "michi",
23
- "cats",
24
- "gatos"
25
- ],
26
- "peerDependencies": {
27
- "react": ">=16.8.0",
28
- "react-dom": ">=16.8.0"
29
- },
30
- "devDependencies": {
31
- "@types/react": "^18.3.18",
32
- "@types/react-dom": "^18.3.5",
33
- "react": "^18.3.1",
34
- "react-dom": "^18.3.1",
35
- "rimraf": "^6.0.1",
36
- "typescript": "^4.9.5"
37
- },
38
- "author": "Ariel González Agüero",
39
- "license": "MIT"
40
- }
1
+ {
2
+ "name": "@arielgonzaguer/michi-router",
3
+ "private": false,
4
+ "version": "1.2.0",
5
+ "description": "El router minimalista y simple para React.\nEl objetivo principal de esta herramienta es proporcionar la funcionalidad básica de enrutamiento.",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "prepare": "npm run build",
14
+ "clean": "rimraf dist",
15
+ "prebuild": "npm run clean",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "keywords": [
19
+ "react",
20
+ "router",
21
+ "typescript",
22
+ "michi",
23
+ "cats",
24
+ "gatos"
25
+ ],
26
+ "peerDependencies": {
27
+ "react": ">=16.8.0",
28
+ "react-dom": ">=16.8.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/react": "^18.3.18",
32
+ "@types/react-dom": "^18.3.5",
33
+ "react": "^18.3.1",
34
+ "react-dom": "^18.3.1",
35
+ "rimraf": "^6.0.1",
36
+ "typescript": "^4.9.5"
37
+ },
38
+ "author": "Ariel González Agüero",
39
+ "license": "MIT"
40
+ }