app-route icon indicating copy to clipboard operation
app-route copied to clipboard

data does not reset when path is empty

Open mochicode opened this issue 8 years ago • 3 comments

Description

I basically have the same set up like this, but with the subroute inside another page.

<app-location route="{{route}}"></app-location>
<app-route
    route="{{route}}"
    pattern="/:page"
    data="{{routeData}}"
    tail="{{subroute}}">
</app-route>
<app-route
    route="{{subroute}}"
    pattern="/:id"
    data="{{subrouteData}}">
</app-route>

I wanted to show an overview page of items when there is no id present and a detailed view when I click on an item.

Expected outcome

  route = { path: '/overview/' }
  subroute = { path: '' }
  subrouteData = {}

  // after I tap on item
  route = { path: '/overview/1' }
  subroute = { path: '/1' }
  subrouteData = { id: '1' }

  // when I go back
  route = { path: '/overview/' }
  subroute = { path: '' }
  subrouteData = { }

Actual outcome

  route = { path: '/overview/' }
  subroute = { path: '' }
  subrouteData = {}

  // after I tap on item
  route = { path: '/overview/1' }
  subroute = { path: '/1' }
  subrouteData = { id: '1' }

  // when I go back
  route = { path: '/overview/' }
  subroute = { path: '' }
  subrouteData = { id: '1' }

Question

I was looking at the source code and saw that when you reset the properties of the element, that you have commented out the line to reset the data and now I'm wondering if there is a reason behind this?
Because when I uncomment it, it works just fine.

mochicode avatar Jan 27 '17 19:01 mochicode

+1 Some explanation here.

What would be the best workaround?

brettpostin avatar Feb 10 '17 15:02 brettpostin

I also wanted a default page and I had the same problem.

To solve it I added an observer 'propertyRouteDataChanged(route.path)' and force the value to my default page,

propertyRouteDataChanged() {
      if (this.route.path == '') {
        this.set('routeData.page', 'index');
      }
}

H3dz avatar Mar 27 '17 23:03 H3dz

same issue here... and applying a similar workaround as @H3dz ...

GeoloeG-IsT avatar Oct 05 '17 17:10 GeoloeG-IsT