mateothegreat / svelte5-router

An SPA router for Svelte that allows you to divide & conquer your app with nested routers.
https://svelte5-router.vercel.app
40 stars 3 forks source link

How to work with another /basepath? #7

Open wa-rren-dev opened 1 week ago

wa-rren-dev commented 1 week ago

I'm serving my app from a base path of /myapp so looking to set up routes and matchers that are always relative to that. I can't quite get the hang of the setup.

<script>
  const routes = [
    {
      path: `/`,
      component: Home,
    },
    {
      path: `new`,
      component: New,
    }
  ];

  function debug(route) {
      console.log(route);
      return route;
}
</script>

<a use:route href={`/`}>Home</a>
<a use:route href={`/new`}>New</a>

<Router base="/" {routes} pre={debug} />

If I do the above, all good. But my base in vite.config.js is set to "/myapp".

How would I amend the above to accommodate the basepath and also match the routes? I've tried all manner of combinations of putting the myapp prefix in the paths in the routes array, the base prop on the . Is there any info on doing this that I've missed?

Many thanks!

popconst commented 4 days ago

I'm also just using use vite and I'm not why the content does not change when I click a url. @wa-rren-dev did you manage to find a fix?

popconst commented 4 days ago

my issue was that i was doing:

  const routes: Route[] = [
    {
      path: '/swings',
      component: SwingStrategies
    }
  ]

instaed i should have done

    const routes: Route[] = [
    {
      path: 'swings',
      component: SwingStrategies
    }
  ]
wa-rren-dev commented 2 days ago

I'm also just using use vite and I'm not why the content does not change when I click a url. @wa-rren-dev did you manage to find a fix?

I didn't find a fix! Ended up stepping down to Svelte 4 for a few reasons.