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

Add example to demonstrate a client routing pattern #11

Open
sidiousvic opened this issue Jul 2, 2020 · 0 comments
Open

Add example to demonstrate a client routing pattern #11

sidiousvic opened this issue Jul 2, 2020 · 0 comments
Assignees
Labels
🎮 examples Related to example apps 🧪 experiment Experimental feature 🍄 good first issue Good for newcomers

Comments

@sidiousvic
Copy link
Owner

sidiousvic commented Jul 2, 2020

This is a simple, declarative implementation of a routing mechanism that may or may not work well with phantom:

⚠ Precludes that the index page is served by default to all routes.

function phantomComponent() {
  const route = window.location.pathname;
  switch (route) {
    case "/view1":
      return `${View1()}`;
    case "/view2":
      return `${View1()}`;
  }
}

function View1() {
  return `<div id="view-1">{...}</div>`;
}

function View2() {
  return `<div id="view-2">{...}</div>`;
}

Implement an example that demonstrates a pattern like such as the above.

Useful resources:
Create a Modern Vanilla Javascript Router on HACKDOOR
How to Build a Router With Vanilla JavaScript
Implementing Simple SPA Routing Using Vanilla JavaScript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎮 examples Related to example apps 🧪 experiment Experimental feature 🍄 good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants