Giter Site home page Giter Site logo

Readme & Wiki incorrect about stencil-router HOT 5 OPEN

safaalai avatar safaalai commented on May 27, 2024 6
Readme & Wiki incorrect

from stencil-router.

Comments (5)

minecrawler avatar minecrawler commented on May 27, 2024 3

Is this router dead? I just tried to create a stencil application, and the template just leads to bugs and the code doesn't reflect how this router should work and I'm very confused. Can one even create applications with Stencil right now (using this router)?

from stencil-router.

gregorypratt avatar gregorypratt commented on May 27, 2024 2

I've ditched it and rolled my own, there is no evidence to suggest this repo is maintained.

from stencil-router.

gregorypratt avatar gregorypratt commented on May 27, 2024 2

In my app-root.tsx file

@State() path: string = location.pathname;

componentWillLoad() {
  addEventListener('locationChange', () => (this.path = location.pathname));
  addEventListener('popstate', () => (this.path = location.pathname));
}

render() {
  if (this.path === '/') return <home-page />;
  if (this.path === '/login') return <login-page />;
  return <page-not-found />;
}

In a utils.ts file

export function navigate(path: string) {
  history.pushState({}, '', path);
  dispatchEvent(new Event('locationChange'));
}

In components that need to query location

if (location.pathname.includes('login')) { ... }

And for things like URL params I just use regex matching where needed.

It all seems to work quite well.

from stencil-router.

Blackmegg1 avatar Blackmegg1 commented on May 27, 2024 1

In my app-root.tsx file

@State() path: string = location.pathname;

componentWillLoad() {
  addEventListener('locationChange', () => (this.path = location.pathname));
  addEventListener('popstate', () => (this.path = location.pathname));
}

render() {
  if (this.path === '/') return <home-page />;
  if (this.path === '/login') return <login-page />;
  return <page-not-found />;
}

In a utils.ts file

export function navigate(path: string) {
  history.pushState({}, '', path);
  dispatchEvent(new Event('locationChange'));
}

In components that need to query location

if (location.pathname.includes('login')) { ... }

And for things like URL params I just use regex matching where needed.

It all seems to work quite well.

Thanks! It was very helpful.

from stencil-router.

Blackmegg1 avatar Blackmegg1 commented on May 27, 2024

Are there any alternative routers can be used in Stencil application?

from stencil-router.

Related Issues (20)

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.