Skip to content

fix(router): linking to redirects #3335

Closed

Description

@btford

In the below example, the link from the parent to the grandchild would not work:

@View({
  template: `<a [router-link]="['./child']">link to default child</a>`
})
@RouteConfig([
  { path: '/child/...', component: ChildCmp, as: 'child' }
])
class ParentCmp {
}

@View({
  template: `<a [router-link]=""></a>`
})
@RouteConfig([
  { path: '/', redirectTo: '/default' },
  { path: '/:name', component: UserCmp, as: 'name' }
])
class ChildCmp {
}

A way to provide defaults for params might cover this use case:

@View({
  template: `<a [router-link]="['./child']">link to default child</a>`
})
@RouteConfig([
  { path: '/child/...', component: ChildCmp, as: 'child' }
])
class ParentCmp {
}

@View({
  template: `<a [router-link]=""></a>`
})
@RouteConfig([
  // `default` here means "fill in params that aren't present with these values"
  { path: '/:name', component: UserCmp, as: 'name', defaults: { name: 'default' } }
])
class ChildCmp {
}

Alternatively, we could mark certain child routes as "default", so this would work:

@View({
  template: `<a [router-link]="['./child']">link to default child</a>`
})
@RouteConfig([
  { path: '/child/...', component: ChildCmp, as: 'child' }
])
class ParentCmp {
}

@View({
  template: `<a [router-link]=""></a>`
})
@RouteConfig([
  { path: '/', redirectTo: '/default', default: true }, // `default` here means choose this for children
  { path: '/:name', component: UserCmp, as: 'name' }
])
class ChildCmp {
}

Activity

  1. changed the title [-]feat(router): linking to redirects[/-] [+]fix(router): linking to redirects[/+] on Jul 28, 2015
  2. added this to the alpha-35 milestone on Jul 28, 2015
  3. btford commented on Aug 5, 2015

    @btford
    ContributorAuthor

    tracks internal bug: b/22617861

  4. btford commented on Aug 5, 2015

    @btford
    ContributorAuthor

    @IgorMinar @matsko I'd like your help designing this.

  5. self-assigned this
    on Aug 11, 2015
  6. modified the milestones: alpha-36, alpha-35 on Aug 12, 2015
  7. btford commented on Aug 13, 2015

    @btford
    ContributorAuthor

    I'm still trying to design a good design for this; it's tricky because you can't easily work backwards from an arbitrary partial URL to a set of components to properly generate the instruction.

    For now, I have a solution that only handles the case where you have a link like this:

    @RouteConfig([
      new Redirect({path: '/', redirectTo: '/second'}),
      new Route({path: '/second', component: DummyCmpB, as: 'secondCmp'})
    ])
    class ParentRedirectCmp {
    }
    
    @View({{
      template: `<a [router-link]="['./first'] >this links to /first/second</a>`
    })
    @RouteConfig([
      new Route({path: '/first/...', component: ParentRedirectCmp, as: 'firstCmp'})
    ])
    class AppCmp {
    }
    
    

    So if you redirect from a child to another route within that child, everything works just fine.

    But trying to deeplink a redirect from parent into a deep hierarchy will not work.

  8. angular-automatic-lock-bot commented on Sep 7, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions