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

Deploy in subdirectory? #88

Closed
MoritzStefaner opened this issue Sep 3, 2021 · 7 comments
Closed

Deploy in subdirectory? #88

MoritzStefaner opened this issue Sep 3, 2021 · 7 comments

Comments

@MoritzStefaner
Copy link

Hi,

thanks for this handy router.

I have a scenario where I want to deploy a svelte app in a subdirectory on a server, e.g. example.com/app1/ example.com/app2/.

How would I configure tinro to manage routes only under inside their own path? (e.g. /app1/route1). I tried relative paths, but this didn't seem to trigger the routes.

Thank you for any pointers!

@AlexxNB
Copy link
Owner

AlexxNB commented Sep 3, 2021

Right now it should work if you will use full path in links and Routes:

<a href="/app1/route1">Route1</a>
<a href="/app1/route2">Route2</a>

<Route path="/app1/*">
    <Route path="/route1">This is route #1</Route>
    <Route path="/route2">This is route #2</Route>
</Route>

Course you can use constant to define base:

<script>
   import {BASE} from './my_constants.js'; // BASE='/app1';
</script>

<a href="{BASE}/route1">Route1</a>
<a href="{BASE}/route2">Route2</a>

<Route path="{BASE}/*">
    <Route path="/route1">This is route #1</Route>
    <Route path="/route2">This is route #2</Route>
</Route>

But I'll try to implement more explicit base defining. It will be something like this in near future:

<script>
   import {router} from 'tinro';
   router.setBase('app1');
</script>

<a href="/route1">Route1</a>
<a href="/route2">Route2</a>

<Route>
    <Route path="/route1">This is route #1</Route>
    <Route path="/route2">This is route #2</Route>
</Route>

@MoritzStefaner
Copy link
Author

MoritzStefaner commented Sep 3, 2021 via email

@MoritzStefaner
Copy link
Author

(I just noticed that enabling hash navigation using router.mode.hash() works for that case, so that's a partial win already :)

@AlexxNB AlexxNB closed this as completed in d63dead Sep 3, 2021
@AlexxNB
Copy link
Owner

AlexxNB commented Sep 3, 2021

I added method router.base('/app1'); in 0.6.7 to set relative base path in the root component of your app.

@AlexxNB
Copy link
Owner

AlexxNB commented Sep 3, 2021

@AlexxNB
Copy link
Owner

AlexxNB commented Sep 3, 2021

It is impossible to determine that app is under subdirectory when using history API. All routers have config option to set base path.

@MoritzStefaner
Copy link
Author

Makes sense, and thanks for the quick help!

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