millermedeiros / crossroads.js

JavaScript Routes
http://millermedeiros.github.com/crossroads.js/
1.44k stars 156 forks source link

Support of wildcard in the beginning of the URL #152

Open olignyf opened 8 years ago

olignyf commented 8 years ago

Hi,

I'm halfway done in the Crossroads router+History.js implementation and I see something which seems not supported - or that I at least don't know how to do. It is to have a wildcard for the beginning of the route, or as a workaround configure a base-URL at the init stage.

Router.addRoute('*cities/{id}', function(cityId) { (...) } });

Because in dev mode my URL can be http://localhost/dev/sandbox/home-panel/public/ http://localhost/dev/sandbox/home-panel/public/cities/2643339 etc.

And in production domain.com domain.com/cities/2643339 etc.

Thanks!

sumitkm commented 8 years ago

Hi @olignyf This usually isn't a problem. Routing works off the url fragment after top level domain. So if the top level domain changes it doesn't make a difference to the router. However in your application, if you want to see the full route somehow, you can use window.location.href.

Also if you inspect the state object returned from HistoryJS' adapter's getState(), you see all the URL components in it.

To test out how your router behaves with something other than localhost, you can put a host file entry pointing 127.0.0.1 to say dev.domain.local in your dev machine.

(edit the C:\windows\system32\drivers\etc\hosts file, you have to open it using elevated privileges)

dev.domain.local    127.0.0.1

Cheers

olignyf commented 8 years ago

Oh but my problem is not with the domain name but with the URL fragment. If you take a look at the URL provided my website can run from a subdirectory which is what is not working.