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

Updating data property of subroute won't propagate when subroute is not active #75

Closed
1 of 8 tasks
timeu opened this issue Apr 6, 2016 · 4 comments
Closed
1 of 8 tasks

Comments

@timeu
Copy link

timeu commented Apr 6, 2016

Description

Not sure if by design or a known limitation:

I have a parent route with a :page data property and a subroute with an :id property.

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

If I update the data property of a subroute the browser location bar won't propagate, if the subroute is not active/matched.

Expected outcome

Original URL: http://localhost:8000/somePage

this.$.subrouter.data =  {id:2};

New URL: http://localhost:8000/somePage/2

Actual outcome

Original URL = New URL = http://localhost:8000/somePage

Reason

This seems to be due to the fact that the subroute is not active and __updatePathOnDataChange will bail out early.

Workaround:

change the tail.path of the parent carbon-route instead of the data property of the subroute.

Browsers Affected

  • Chrome
  • Firefox
  • Safari 9
  • Safari 8
  • Safari 7
  • Edge
  • IE 11
  • IE 10
@TimvdLippe
Copy link

It should work if you use a trailing slash? http://localhost:8000/somePage/

This is indeed confusing and I also encountered with the matching in that sense

@timeu
Copy link
Author

timeu commented Apr 7, 2016

Yeah a trailing slash fixes it.
However IMHO this is not really a satisfying solution because I don't have a control of which URL users puts into the browser location bar and I want to avoid some brittle workaround to add a trailing slash to every URL.

Also the carbon-router itself does not add any trailing slashes itself, so if I want to navigate to a sub-route it won't work. Let's assume that the user starts at:

http://localhost:8000/

Then through databinding on the root carbon-router I change the page property to users. This will change the browser location bar to:

http://localhost:8000/users (note the missing trailing slash)

Now if I want to navigate to the detail page (i.e. http://localhost:8000/users/2) through data-binding on the id property of the sub carbon-router it does not work because of the missing trailing slash.

Maybe I am missing something obvious here.

@TimvdLippe
Copy link

Yes I encountered this too and I think issue #37 is designated to fix/clear up this behavior.

@rictic
Copy link
Collaborator

rictic commented Apr 11, 2016

As designed, changes to data on inactive routes don't propagate. The thinking here is that this is the less surprising thing, as it would be easy to get into a situation where changing a property that happens to be bound into a distant carbon-route could end up with an unexpected redirect.

The subtle distinctions between /foo, /foo/ and /foo/bar here aren't great though. As Tim mentioned we're tracking that at #37 while we consider solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants