preact-router icon indicating copy to clipboard operation
preact-router copied to clipboard

routing base path

Open moebiusmania opened this issue 7 years ago • 8 comments

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

moebiusmania avatar Jan 25 '18 17:01 moebiusmania

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

studentIvan avatar Jan 27 '18 21:01 studentIvan

Hi any updates on this base path ?

KowsalyaPK avatar Mar 19 '18 10:03 KowsalyaPK

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

studentIvan avatar Mar 29 '18 15:03 studentIvan

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

jiarongxu avatar Apr 26 '18 22:04 jiarongxu

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

studentIvan avatar May 05 '18 09:05 studentIvan

@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!

jahilldev avatar May 11 '18 07:05 jahilldev

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

developit avatar May 21 '18 17:05 developit

@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.

studentIvan avatar May 25 '18 13:05 studentIvan