Patrick Blind
Patrick Blind

Reputation: 399

How to create a route in ionic 3

I've built an ionic 3 app with sidemenu.
Right now, the navigation was implemented by push/pop.

When I go to landing page (www.XXX.com), it's loading the newest 20 events and add them to the list on landing page.

But I need to go to (www.XXX.com/:id) and add that specific event to the list only.

I'm stuck with this and wondering how to implement on ionic 3.

Any thoughts on this?

Thanks

Upvotes: 0

Views: 658

Answers (1)

Shubham Chaudhary
Shubham Chaudhary

Reputation: 499

You can read the URL of the page and get the param in the url, using the following code

// Get your param by manipulating URL string
let sId = location.href.split("#")[1].split("/")[1];

OR

If you need much cleaner approach, use segment in IonicPage.

Declate IonicPage as 

    @IonicPage({
        segment: 'page/:id'
    })

and retrieve param as

constructor(navParams: NavParams){
    let sId = this.navParams.get('id');
}

Upvotes: 1

Related Questions