Skip to content

Commit

Permalink
Add state.source.get example
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Oct 3, 2019
1 parent 4440544 commit 785fe57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,17 @@ Si abrimos la pestaña Network y hacemos click en el menu para ir a `Inicio`, po

Miramos en `frontity.state.source.data` y vemos que hay muchos datos populados.

Vamos a usar todo esto en nuestro código.
En vez de usar `state.source.data[url]` vamos a usar `state.source.get(url)` que se asegura de que las urls incluyan siempre la barra final.

_-> En vez de usar `state.source.data[url]` vamos a usar `state.source.get(url)` que se asegura de que las urls incluyan siempre la barra final. Es decir, `/mi-url/` es igual que `/mi-url`._
Vamos a inspeccionar la página inicial usando `state.source.get("/")`:

<p align="center">
<img alt="Frontity en la consola" src="assets/console-4.png">
</p>

Como vemos, tiene muchas propiedades interesantes como `isHome`, `isArchive`, o un array de `items`. Si fuese una categoría tendría un `isCategory`, si fuese un post tendría un `isPost`, etc.

Finalmente, vamos a usar todo esto en nuestro código.

Obtenemos la información del link actual (`state.router.link`) y lo usamos para ver si es una lista, un post o una página.

Expand Down
Binary file added assets/console-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 785fe57

Please sign in to comment.