GithubHelp home page GithubHelp logo

alshdavid / pico-router Goto Github PK

View Code? Open in Web Editor NEW
327.0 4.0 13.0 4.61 MB

Simple framework agnostic UI router for SPAs

License: MIT License

TypeScript 81.60% JavaScript 12.72% Makefile 4.52% Shell 1.15%
react svelte svelte-v3 vue router spark

pico-router's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pico-router's Issues

TypeError: app.history.currentEvent is undefined

Description
When trying to use the demo I only get the error TypeError: app.history.currentEvent is undefined in the console.

To Reproduce
Steps to reproduce the behavior:

  1. git clone https://github.com/alshdavid/crayon.git
  2. cd crayon/examples/svelte-animated/
  3. npm install
  4. npm run dev
  5. Point your browser to the server.

Expected behavior
A demo of how to use Crayon with Svelte and animations...

Desktop

  • OS: Debian GNU/Linux 9.9 (stretch)
  • Crayon: latest

[core] ensure homescreen mode works

When a web app is added to a mobile device's homescreen and is in full screen mode, ensure the router works.

I experienced issues previously with react router, where I had to use a different method of routing for installable PWAs.

Just want to make sure it's not a problem here

Route parameter converted to lowercase

Describe the bug
When programmatically routing using router.navigate, parameters are converted to lowercase. Could be due to URL encoding methods.

This code:

const id = 'WVPvZIHkGdoi1UlSsSdF';
nav.navigate(`/deal/${id}`);

produces this URL: /deal/wvpvzihkgdoi1ulsssdf

this is the route code:

app.path('/deal/:id', async (req, res) => {
      if(!$user && req.routePattern !== '/auth') {
        res.redirect('/auth');
      } else {
        const Deal = await import('./views/Deal.svelte');
        res.mount(Deal.default, { req, nav: app });
      }
    });

To Reproduce
Steps to reproduce the behavior:

  1. Create route with param
  2. Create button to navigate to route with param that has upper case letters
  3. Click button
  4. Check URL for lowercased param

Expected behavior
Expect route param to not be changed

Desktop (please complete the following information):

  • OS: Mac OS 10.13.6
  • Version of Crayon: 4.1.3
  • Version of Crayon-Svelte: 1.0.10

Additional context
Was solved at one point by this PR: https://github.com/alshdavid/crayon/pull/31

Route called even when middleware use redirection

Describe the bug
Routes are still mounted even with a middleware that should prevent access to them (via a simple redirect). The redirection works well, but it shouldn't even access the component before the redirection is done.

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple protected route with a console.log inside. Let's say /user
  2. Use a custom middleware that simply redirect to another route. Let's say /
  3. Access /user, you will see your console.log inside your protected route display in console.

Expected behavior
The route shouldn't mount or execute anything since there is a middleware and it purpose is to perform actions before accessing the actual path.

Desktop (please complete the following information):

  • OS: MacOS
  • Crayon: ^2.0.5
  • Crayon svelte: ^1.0.1
  • Svelte: ^3.6.3
  • Typescript: ^3.5.3
  • Parcel plugin svelte: ^3.0.1
  • Parcel bundler: ^1.12.3

Additional context
main.js:

import App from './App';
import crayon, { group } from 'crayon';
import svelte from 'crayon-svelte';
import Editor from './components/editor/Editor';
import Login from './components/auth/Login';

const app = crayon.create();
app.use(svelte.router());
const auth = group('/auth', group => {
    group.path('/login', async (req, res) => {
        await res.mount(App, {req, nav: app, component: Login});
    });
});

const secured = group('/bot');
secured.use((_, res) => {
    const session = localStorage.getItem('session');
    if (!session) {
        res.redirect('/auth/login');
    }
});
secured.path('/editor', async (req, res) => {
    await res.mount(App, {req, nav: app, component: Editor});
});
app.use(secured);
app.use(auth);
app.load();

App.svelte:

<script>
    export let component;
    export let req;
    export let nav;
</script>

<div>
     <svelte:component this={component} nav={nav} req={req}/>
</div>

Editor.svelte:

<script>
console.log("should not display");
</script>

Login.svelte:

<div>login page</div>

Is this project dead?

Is this project dead? It looks like multiple of its packages are missing from npm.

svelte-basic example doesn't work - error in commonjs - Cannot read property 'type' of null

Description

The svelte-basic example from the repo doesn't build/work, giving an error [!] (plugin commonjs) TypeError: Cannot read property 'type' of null

To reproduce

$ git clone [email protected]:alshdavid/crayon.git
$ cd crayon/examples/svelte/svelte-basic
$ npm install
...
$ npm run dev
rollup v1.20.3
bundles src/main.js โ†’ public/bundle.js...
[!] (plugin commonjs) TypeError: Cannot read property 'type' of null
node_modules/crayon-svelte/dist/index.js
TypeError: Cannot read property 'type' of null
    at extractAssignedNames (/private/tmp/crayon/examples/svelte/svelte-basic/node_modules/rollup-pluginutils/dist/pluginutils.cjs.js:48:22)
    at Scope.options.params.forEach.param (/private/tmp/crayon/examples/svelte/svelte-basic/node_modules/rollup-pluginutils/dist/pluginutils.cjs.js:63:17)
    at Array.forEach (<anonymous>)
    at new Scope (/private/tmp/crayon/examples/svelte/svelte-basic/node_modules/rollup-pluginutils/dist/pluginutils.cjs.js:62:28)
    at Object.enter (/private/tmp/crayon/examples/svelte/svelte-basic/node_modules/rollup-pluginutils/dist/pluginutils.cjs.js:125:28)
    at visit (/private/tmp/crayon/examples/svelte/svelte-basic/node_modules/estree-walker/src/estree-walker.js:22:9)
    at visit (/private/tmp/crayon/examples/svelte/svelte-basic/node_modules/estree-walker/src/estree-walker.js:44:4)
    at visit (/private/tmp/crayon/examples/svelte/svelte-basic/node_modules/estree-walker/src/estree-walker.js:39:34)
    at visit (/private/tmp/crayon/examples/svelte/svelte-basic/node_modules/estree-walker/src/estree-walker.js:44:4)
    at visit (/private/tmp/crayon/examples/svelte/svelte-basic/node_modules/estree-walker/src/estree-walker.js:44:4)

1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] autobuild: `rollup -c -w`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] autobuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/panta/.npm/_logs/2019-08-30T09_04_35_033Z-debug.log
ERROR: "autobuild" exited with 1.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `run-p start:dev autobuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/panta/.npm/_logs/2019-08-30T09_04_35_094Z-debug.log

Expected behavior

To get the development server running

Desktop / environment

  • macOS Mojave 10.14.6
  • Crayon master (at 983fe37)

More detailed Svelte example

Need a more detailed Svelte example. Perhaps with 2-3 components and an animated transition. Info on where to put code (App.svelte?), etc...

push/pop middleware for Preact

Add push/pop support for preact

const app = crayon.create()

app.push(Component)
app.push(ComponentB)

app.pop()
app.pop()

Svelte nested routing example

I'd love to see a clear example of how to make a nested routing in svelte (or framework agnostic) to better comprehend how it works.
Readme points out how to do it, but marginally and without a real example.
Please ๐Ÿ™๐Ÿ™๐Ÿ™

Any way that you could handle reload

Hi,

Nice project that arrives right on time when I started playing seriously with Svelte.
Works greate, beside this little problem. When I hit reload (or the server reload the site because of sources changes) it gives a 404...

I guess that's not easy without a express like server running, but in that case couln't you support a # route instead of / ?

Thanks again,

Return to Page Location

Is it possible to route to a specific location on a different page, or to route back using the history to get to the same page location that you originally routed from?

Thanks!

Take the Router Challenge

It's not healthy for the Router market to be so dominated by the React Router. I want to level the playing field so that your Crayon router gets a fair crack of the whip. That's why I've written the Router Challenge. It aims to do for Routers what TodoMVC did for UI frameworks by offering the same SPA built in React using different Routers. For it to be successful I need your help. Will you take the Router Challenge and implement the SPA using your Crayon router, please?

Support for protected routes

Is your feature request related to a problem? Please describe.
Trying to add protected routes based on async auth data. Redirects don't prevent other routes from matching and rendering.

Describe the solution you'd like
Using the middleware option, be able to prevent rendering of predefined routes by using redirect or a separate mount call.

Additional context
Here is my router code, the middleware I have above isn't preventing other routes from rendering:

app = crayon.create();

    app.use(crayonSvelte.router(appEl));

    app.use(transition.loader());

    app.use(animate.defaults({
      name: transition.slideLeft,
      duration: 300
    }));

    app.use(animate.routes([
      { from: '/**', name: transition.slideRight  },
      { to: '/**', name: transition.slideLeft }
    ]));

    app.use((req, res, state) => {
      console.log(req);
      console.log(res);
      console.log(state);
      if(!$user && req.routePattern !== '/auth') {
        res.redirect('/auth');
      }
    });

    app.path('/', async (req, res) => {
      const Home = await import('./views/Home.svelte');
      res.mount(Home.default, { req, nav: app });
    });

    app.path('/auth', async (req, res) => {
      const Auth = await import('./components/Auth.svelte');
      res.mount(Auth.default, { req, nav: app });
    });

    app.path('/deals', async (req, res) => {
      const List = await import('./views/List.svelte');
      res.mount(List.default, { req, nav: app });
    });

    app.path('/search', async (req, res) => {
      const Search = await import('./views/Search.svelte');
      res.mount(Search.default, { req, nav: app });
    });

    app.path('/search/:category', async (req, res) => {
      const SearchCategory = await import('./views/SearchCategory.svelte');
      res.mount(SearchCategory.default, { req, nav: app });
    });

    app.path('/agenda', async (req, res) => {
      const Agenda = await import('./views/Agenda.svelte');
      res.mount(Agenda.default, { req, nav: app });
    });

    app.path('/profile', async (req, res) => {
      const Profile = await import('./views/Profile.svelte');
      res.mount(Profile.default, { req, nav: app });
    });

    app.path('/deal/:id', async (req, res) => {
      const Deal = await import('./views/Deal.svelte');
      res.mount(Deal.default, { req, nav: app });
    });

    app.load();

Not a function: res.redirect , res.mount

Hi, I am looking for clientside routing and found crayon.

Describe the bug
I just cloned the Repo for Svelte and run npm install for the basic example.
For some reason, it says in the console res.redirect, or res.mount is not a function

image

When npm install, it would install the latest version of both, crayon and crayon svelte.

When I try to use the examples provided in codesandbox here:

  "dependencies": {
    "crayon": "3.0.5",
    "crayon-svelte": "1.0.5",
    "rxjs": "6.5.2",
    "svelte": "^3.0.0"
  },

When installing the provided example from this repo it will install:

so my guess is, something broke.

Crayon with Svelte 3

I am defining the route like this

app.router.path('/', (req, res) => res.mount(() => res.mount(Test, { ...app, ...req })))

but I am getting this error

Uncaught (in promise) TypeError: Component is not a constructor
    at mounter.js:44
    at SvelteMounter.<anonymous> (mounter.js:23)
    at Generator.next (<anonymous>)
    at mounter.js:7
    at new Promise (<anonymous>)
    at __awaiter (mounter.js:3)
    at SvelteMounter.push (mounter.js:19)
    at mount.js:20
    at Generator.next (<anonymous>)
    at mount.js:7
livereload.js:1 Failed to load resource: net::ERR_CONNECTION_REFUSED

[all] default exports or no default exports?

I often don't use default exports, I'll use

import * as stuff from 'place'

This simply gives me all of the exported things on a module and reminds me of Go. This might not be something everyone likes, so might be worth re-exporting the important bits as default exports

Crayon-Svelte Component Intro

Hello,

I was curious if it is possible to add the intro:true to the client-side app when mounting? I have a transition that plays on the initial load.

Thanks!

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.