roxiness / routify

Automated Svelte routes
https://routify.dev
1.87k stars 87 forks source link

v3 - $params when reset route not take [param] #518

Closed foxkdev closed 1 year ago

foxkdev commented 1 year ago

Problem is when you reset module inside a view with param in folder, $param not take folder params.

bug description I have this structure in routes: folder with [channel] and file view.svelte inside.

in view.svelte:

<!-- routify:meta reset="full" -->
<script>
  import { params } from '@roxi/routify'

  const channel = $params.channel
  console.log($params)

</script>
<span>Not work</span>

if im access to /test/view => console.log display $params empty If im access to /test/view?query=test => console.log display $params with query

Success Result Wanted: If im access to /test/view => console.log display $params with channel

Problem is only when is folder with param, WHEN RESET. if not reset works done.

package.json

{
@roxi/routify": "^3.0.0-next.1",
}

version Last version routify and svelte, but is not a problem of versions i think.

jakobrosenberg commented 1 year ago

Hi @foxkdev

This is by design. When you reset, you clear everything before the reset and the reset component becomes the root component. Since the respective component [channel] doesn't exist after the reset, it won't provide the parameter to the route.

It's possible that we can create a solution for this, but it has to work with

For instance, if you have a site that's protected by the load function, you might want to reset (disable) the root load at /tenants and at /tenants/[id]/ you want to reset the view, but in both case you want to access the parameters from the entire URL.

Currently the route fragments (components) before the reset component are simply removed before the route is processed. This doesn't allow for much flexibility, but we could instead tag the fragments like this:

// pseudo route fragment
{
  node: RNode,
  params: {},
  shouldLoad: true, // new prop
  shouldRender: true, // new prop
  shouldProvideParams: true // new prop
}

I can't tell if this is straight forward yet, but I'll have a look.

foxkdev commented 1 year ago

I think for better usage when im reset is becase I want reset module(layout), not params.

for example i have this routes:

- [channel]/profile.svelte
- [channel]/iframe.svelte
- _module.svelte
- _module-full.svelte

view /[channel]/profile use module but [channel]/iframe i want use module-full, so in this view im reset, but im need access to params.

I think this is normal usage, I suggest:

have meta param reset to reset all(module and params) and create new param "module"(by default 'module') to assign module custom but with rest of params.

jakobrosenberg commented 1 year ago

:tada: This issue has been resolved in version 3.0.0-next.157 :tada:

The release is available on:

Your semantic-release bot :package::rocket: