canjs / can-route

Observable front-end application routing for CanJS.
https://canjs.com/doc/can-route.html
MIT License
10 stars 4 forks source link

Feature request - Allow us to change the "!" character in route to "/" #195

Open green3g opened 6 years ago

green3g commented 6 years ago

Open for discussion but I think a url in a route using the slash character instead of the ! character would be more readable.

www.page.com/#/route/page

vs

www.page.com/#!route/page
justinbmeyer commented 6 years ago

With 5.0, you could change this "relatively" easily by forking https://github.com/canjs/can-route-hash/blob/master/can-route-hash.js and then swapping ! for /.

You could then set an instance of that observable to .urlData:

import {route} from "can";
import YourHash from "./your-hash";

route.urlData = new YourHash();

Btw, since those values are already on the prototype, have you tried changing them locally?

import HashObservable from "can-route-hash";

var hash = new HashObservable();
hash. root = "#/";

route.urlData = hash;
green3g commented 6 years ago

I tested the second method, it doesn't appear to work. The initial "/" changes back to an ! after initializing.

The second method, I could get working:

16: return loc.href.split(/#\/?/)[1] || '';

41: root: '#/',

65: loc.hash = '/' + path;
justinbmeyer commented 6 years ago

Btw, I totally support this feature. What do you think an API to make it work should look like?

green3g commented 6 years ago

To be honest, I'm not sure why the ! is in the route to begin with. I'm sure there's a reason but I'd like the route.register to match the actual route. So I'd say the api would look like this:

route.register('/{id}/action/{action}'); // --> #/8/action/add
route.register('!whatever/{id}'); // --> #!whatever/8
route.register('{id}/action/{action}'); // --> #8/action/delete

This would be a breaking change though...so I'm not saying this is the way to go but that's what I'd say is the most flexible. Then I wouldn't need a starting character at all if I don't want one.