Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme & Wiki incorrect #154

Open
safaalai opened this issue Feb 25, 2023 · 5 comments
Open

Readme & Wiki incorrect #154

safaalai opened this issue Feb 25, 2023 · 5 comments

Comments

@safaalai
Copy link

Resources:
Before submitting an issue, please consult our docs.

Stencil version: (run npm list @stencil/core from a terminal/cmd prompt and paste output below):

I'm submitting a ... (check one with "x")
[ x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://stencil-worldwide.slack.com

Current behavior:

None of the imports or the way the code is described to work on the router actually work in practice. In addition, there is no backward compatibility despite the wiki showing that the functions exist.

Expected behavior:

Should work as shown on readme. Wiki should show what is actually available.
Better yet: be backward compatible. Why strip out the old functions?

Steps to reproduce:

npm init stencil
... complete prompts to create simple standalone stencil app
npm install
npm start ==> everything works
npm uninstall @stencil/router
npm install @stencil-community/router --save-dev
npm start ==> things break
.. try to do what the readme suggests:
... cannot import createRouter or Route

Related code:

insert any relevant code here

Other information:

@minecrawler
Copy link

minecrawler commented Aug 3, 2023

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)?

@gregorypratt
Copy link

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

@Blackmegg1
Copy link

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

@gregorypratt
Copy link

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.

@Blackmegg1
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants