0

I'm new to lit and JavaScript, but a few days ago, I was reading through the documentation and came across @lit-labs/router. The truth is, I wanted to try it to continue learning, but reading the little documentation that there is about @lit-labs/router I didn't understand how to implement it.

So my question is how do I implement routing with @lit-labs/router?

The link to @lit-labs/router:
@lit-labs/router

I can only make an example work

class MyElement extends LitElement {
  private router = new Router(this, [
    {path: '/', render: () => html`<h1>Home</h1>`},
  ]);

  render() {
    return this.router.outlet();
  }
}
shA.t
  • 16,580
  • 5
  • 54
  • 111
  • This is a difficult question to answer for two reasons. The first is that (as of this question) @lit-labs/router is still in [prototyping phase](https://lit.dev/docs/libraries/labs/). Because it is still subject to frequent breaking changes I would not recommend it for learning. Additionally, I'm not sure how to answer the question of "how to implement routing" when you've also provided a working example? Generally you'd have a top level component `` that contains a `Router`. Then for `path: '/'` you'd render a `` element containing its own `Routes`. – YouCodeThings Oct 31 '22 at 17:50

0 Answers0