Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle default root and catch-all parameters with deep link system #11363

Closed
WhatsThatItsPat opened this issue Apr 25, 2017 · 4 comments
Closed

Comments

@WhatsThatItsPat
Copy link

Ionic version: (check one with "x")
[ ] 1.x
[ ] 2.x
[x] 3.x

I'm submitting a ... (check one with "x")
[ ] bug report
[x] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Related code:

The new deep link system doesn't handle default root pages nor catch-all parameters while the previous system did.

I'd like to be able to have a page with an empty segment that acts as a default root/home page:

@IonicPage({
  // An empty segment means we will load this as the default root page.
  // Only one empty-segmented page would be allowed per app.
  segment: ''
})

This would mean I wouldn't have to add rootPage: any = HomePage; to app.component.ts.

Secondly, I'd like to have a segment that acts as a fallback if another segment isn't found:

@IonicPage({
  // Load when the path doesn't match any other segments in the app.
  segment: ':usernameOr404'
})

As the param name above suggests, this is how one might display user pages based on a username (or a 404 page if a username is not found or invalid).

I was able to do this with the previous system doing something like this:

IonicModule.forRoot(MyApp, {}, {
  links: [
    {
      // example.com
      segment: '',
      component: HomePage,
      name: 'Home'
    },
    {
      // example.com/someuser
      segment: ':username',
      component: UserPage,
      name: 'User'
    },
    {
      // example.com/list
      segment: 'list',
      component: ListPage,
      name: 'List'
    },
    {
      // example.com/list/id123
      segment: 'list/:id',
      component: DetailPage,
      name: 'Detail'
    }
    // ... other pages ...
  ]
})
@WhatsThatItsPat
Copy link
Author

Here's a dup at ionic-app-scripts for the first part about empty segments.

@jgw96
Copy link
Contributor

jgw96 commented Apr 26, 2017

Hello, thanks for opening an issue with us, we will look into this.

@ey-aroberts
Copy link

@PatrickMcD
Using a segment with just a parameter allows you to have a blank segment as the home. You can actually have multiple pages share segment names and have a check to see which component you should navigate to.

Here is how I do it currently. I navigate my whole app through a nav-utility.

let segments = this._serializer.parse(moveToPage);

if(segments[0].name === "PageContentPageComponent" && segments[0].id === ""){
  segments[0].name = "HomePageComponent";
}

// this combines the data the segment has with any data that is not a segment parameter
nav.setRoot(segments[0].name, Object.assign({}, segments[0].data, moveToPageParam))

Here are the pages I have that map
@IonicPage({
segment: ':id'
})
@component({
templateUrl: 'home.html'
})
export class HomePageComponent

@IonicPage({
segment: ':id'
})
@component({
templateUrl: 'page-content.page.html',
})
export class PageContentPageComponent

@ionitron-bot
Copy link

ionitron-bot bot commented May 7, 2018

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Thank you for using Ionic!

@ionitron-bot ionitron-bot bot closed this as completed May 7, 2018
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators May 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants