V
V
Vadim2019-06-19 10:39:40
Angular
Vadim, 2019-06-19 10:39:40

How to get a request from the address bar and process it?

Good afternoon!
There is a task (in Angular) that seems not difficult, but I don’t understand how to approach it! The user enters such parameters in the address bar and it should be automatically redirected to the address Created Routing and 2 components Main and Second. Further I will not understand where to dig!
http://localhost:4200/?page=main&id=3
http://localhost:4200/main/3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maks Kovyvchak, 2019-06-25
@max_front

I would do something like this

ngOnInit() {
    this.activatedRoute.queryParams.subscribe(params => {
        if(Object.keys(params).length){
         window.location.href = window.location.origin + '/' + (Object.values(params)).join('/')
        }
      });   
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question