Giter Club home page Giter Club logo

router's Introduction

@depack/router

npm version

@depack/router is The Preact Router Component For Compilation With Depack.

yarn add -E @depack/router

The original source code is from preact-router but it was modified to be able to compile front-ends that use it with Depack using Google Closure Compiler.

DEMO: https://dpck.github.io/router/

Connect your Preact components up to that address bar.

preact-router provides a component that conditionally renders its children when the URL matches their path. It also automatically wires up elements to the router.

Table Of Contents

API

The package is available by importing its default function and named functions:

import Router, { Link } from '@depack/router'

Router

import Router, { Link } from '@depack/router'
import { render } from 'preact'

const Main = () => (
  <div>
    <ul>
      <li><Link href="/router/">Home</Link></li>
      <li><Link href="/about">About</Link></li>
      <li><Link href="/search/example/hello">Search</Link></li>
    </ul>
    <Router onChange={(e) => {
      if (e.current && e.current.attributes.title) {
        document.title = e.current.attributes.title
      }
    }}>
      <Home path="/router/" title="@depack/router" />
      <About path="/about" title="About" />
      <Search path="/search/:query/:optional?" title="Search" />
    </Router>
  </div>
)

const Home = () => (<div>
  <h3>Home</h3>
  Preact Router For Depack.
</div>)
const About = () => (<div>
  <h3>About</h3>
  <p><em>Preact</em> is a library for making single-page
  websites and rendering JSX components.</p>
  <p><em>Depack</em> is front-end bundler that uses Google
  Closure Compiler (as well as back-end package compiler).</p>
</div>)
const Search = ({ optional }) => (<div>
  <h3>Search</h3>
  {optional ? `You've searched for: ${optional}` : ''}
</div>)

render(<Main />, document.querySelector('#preact'))

If there is an error rendering the destination route, a 404 will be displayed.

Copyright

Art Deco © Art Deco for Depack 2019 Tech Nation Visa Tech Nation Visa Sucks

router's People

Contributors

zavr-1 avatar

Stargazers

 avatar

Watchers

James Cloos avatar Anton 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.