preactjs / preact-router

:earth_americas: URL router for Preact.
http://npm.im/preact-router
MIT License
1.01k stars 156 forks source link

routing base path #263

Open moebiusmania opened 6 years ago

moebiusmania commented 6 years ago

Hi there, I would like to set a base path to preact-router to serve a webapp from a "subfolder" of the root domain (ie: application from company.com/application). I've noticed that I'm not the first one asking this question but searching through the issues I didn't understand if this feature has been developed or not and eventually how to use it.

Unfortunately when serving from from a company.com/application type location, preact-router redirects to the base company.com domain, breaking many static assets links.

The only solution I have found has been to switch to hash routing, but I would prefer to keep the default routing behavior.

thanks

studentIvan commented 6 years ago

+1 for this issue, will try to do PR in my free time (tomorrow) if nobody does it

KowsalyaPK commented 6 years ago

Hi any updates on this base path ?

studentIvan commented 6 years ago

@KowsalyaPK right now I use custom route function, you can do same stuff :)

jiarongxu commented 6 years ago

@studentIvan Do you have a sample for the custom route function? Thank you.

studentIvan commented 6 years ago

@jiarongxu will this taken from context gist be enough for you? https://gist.github.com/studentIvan/a5f7b7dad184e0b0ef87a3d681209c04

jahilldev commented 6 years ago

@studentIvan How is this used with preact-router? Could you provide some context to how and where the functions are called in your gist? Many thanks!

developit commented 6 years ago

Ah neat solution @studentIvan - I hadn't thought of injecting into History, haha.

studentIvan commented 6 years ago

@jhdevuk I don't use the preact-router, only my local fork of it ( should be this probably https://github.com/studentIvan/preact-router/tree/feauture-extends-router-class ). The main differences are functions export possibility and extending. I set base-href in my appRegistry service first https://gist.github.com/studentIvan/e54fde89335fe0432d9665e04daa5b2b then I check it right in the route function.