According to the documentation and demos provided by Vaadin the route parameters should be bound to the location.params. The examples provided are using polymer, and when I use LitElement the location.params is undefined. Is there a trick other than to parse the url to extract the used url :parameter using JavaScript in combination with Lit?
            Asked
            
        
        
            Active
            
        
            Viewed 623 times
        
    1 Answers
2
            You can access it by overriding the onBeforeEnter lifecycle callback:
@customElement('example-view')
export class ExampleView extends LitElement implements BeforeEnterObserver {
  @state()
  private user = '';
  render() {
    return html`
      <h1>Hello, ${this.user ? this.user : 'stranger'}</h1>
    `;
  }
  async onBeforeEnter(location: RouterLocation) {
    this.user = location.params.user as string;
  }
}
        Marcus Hellberg
        
- 1,853
 - 10
 - 16
 
- 
                    Thanks for the quick reply. Your the answer however is based on TypeScript, but I'm looking for a JavaScript solution. – Alex Jongman Dec 21 '21 at 18:52
 - 
                    2The same will work, just leave off the type definitions. – Marcus Hellberg Dec 21 '21 at 20:33