0

How to read a parameter in the URL string when opening the start page? If I pass the ID to the URL: mysite.com/productid, and the app will read and remember this ID for future reference ? I want to read the QR-code, which contains the path with ID of the product and go directly to the site to this product section.

Vasily Asur
  • 31
  • 1
  • 5

1 Answers1

0

First Create A route in app-routing module file like this

{path: 'test/:id', component: TestComponent}

and get id in your Start Component like this and store in local storage

constructor(
private activeRoute: ActivatedRoute
) {}

ngOnInit() { 
const getidfromurl = this.activeRoute.snapshot.paramMap.get('id');
localStorage.setItem('my id',getidfromurl);
}