canjs / mock-url

A mock url made with CanJS 5.
0 stars 1 forks source link

How should mock-url handle pathname? #6

Open indifferentghost opened 5 years ago

indifferentghost commented 5 years ago

It was discussed in the morning standup on 10/26 to add pathname to mock-url or create a mock-url like example to work with can-route-pathname.

The purpose of mock-url is to provide an interactive navigation bar for CanJS demos.

This issue hopes to elucidate how mock-url should be implemented to handle can-route-pushstate:

Here's a demo of mock-url that shows basic navigation.

Proposal

Current Implementation mock-url@5.1.0

indifferentghost commented 5 years ago

5.1.0-beta doesn't handle RoutePushstate.replaceState methods.

indifferentghost commented 5 years ago
var a = document.createElement("a");
a.href ="/foo/bar";
a.display = "none";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);

If pushstate isn't active, it won't capture the link which causes codepen to navigate to another page. The same is true if pushstate has a root property and you try and navigate to something that wouldn't be nested in that root. demo

The aforementioned input navigation was suggested as calling pushState or replaceState (which is how the current input handler [below] works) might not fire everything that CanJS needs to fire.

prop.listenTo(prop.lastSet, function(newVal){
  var newURL = newVal.replace("/", "");    
  window.history.replaceState( null, null, newURL );
});