Giter Site home page Giter Site logo

router's Introduction

@atomico/router

CircleCI npm gzip

Pequeño enrutador para la gestión de rutas con Atomico.

import { h } from "@atomico/core";
import { lazy } from "@atomico/lazy";
import { Router } from "@atomico/router";

let PageHome = lazy(() => import("./pages/home"));
let PageUsers = lazy(() => import("./pages/users"));
let PageConfig = lazy(() => import("./pages/config"));
let NotFound = () => <h1>404</h1>;

function App() {
	return (
		<Router>
			<PageHome path="/" loading="loading home..." />
			<PageUsers path="/users" loading="loading users..." />
			<PageConfig path="/users" loading="loading config..." />
			<NotFound default />
		</Router>
	);
}

Parametros de ruta

tipo comodin ejemplo
requerido /folder/folder
parametro requerido /:folder /:paramA/:paramB
parametro opcional /:folder? /:paramA?/:paramB?
parametro spread /:folders... /:folders...

hooks

useMatchRoute

let [inRoute, params] = useMatchRoute("/:id");

Compara la ruta actual con el patrón de captura, Este hooks no se suscribe a history

useRoute

let [inRoute, params] = useRoute("/:id");

Compara la ruta actual con el patrón de captura, Este hooks si se suscribe a history

useRedirect

Este hook admite un primer parámetro opcional, que modifica su comportamiento.

redirect estatico

Este tipo de redirect aplica memo, por lo que el callback solo mutara si el primer parámetro muta.

let toHome = useRedirect("/");

<button onClick={toHome}> click </button>;

redirect dinamico

Este redirect esta pensado para pathname dinámicos.

let redirect = useRedirect();

<button onClick={() => redirect("/")}> click </button>;

useHistory

se suscribe al historial del navegador.

let [pathname, redirect] = useHistory();

router's People

Contributors

uppercod avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.