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

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

Open
green3g opened this issue Aug 2, 2018 · 4 comments
Open

Comments

@green3g
Copy link

green3g commented Aug 2, 2018

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
Copy link
Contributor

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
Copy link
Author

green3g commented Aug 17, 2018

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
Copy link
Contributor

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

@green3g
Copy link
Author

green3g commented Aug 17, 2018

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.

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

No branches or pull requests

2 participants