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

Plugin has no support for optional parameters #93

Open
CatchABus opened this issue Sep 26, 2022 · 3 comments
Open

Plugin has no support for optional parameters #93

CatchABus opened this issue Sep 26, 2022 · 3 comments

Comments

@CatchABus
Copy link

CatchABus commented Sep 26, 2022

Is your feature request related to a problem? Please describe.
Plugin has no support for optional path parameters.

Describe alternatives you've considered
Svelte navigator could drop hardcoded path parsing and make use of one of most used packages:
https://www.npmjs.com/package/path-to-regexp
https://www.npmjs.com/package/regexparam (a lightweight solution)

@maurictg
Copy link

That would be a huge improvement for svelte-navigator!

I would like to use the following syntax that is common in other frameworks like Vue:

path="/bar/foo/:id?"

@Kokoserver
Copy link

That will make a lot of sense

@rehmulus
Copy link

rehmulus commented Nov 4, 2022

You can achieve this in a complicated way by nesting routes. This should only be used as a workaround in my opinion.

App.svelte

<script>
  import { Router, Route } from "svelte-navigator";
</script>
<Router>
  <Route path="/route/:requiredParam/*" let:params={params1}>
    <Route path="/optionalRoute/:optionalParam" let:params={params2}>
      <RouteComponent requiredParam={params1.requiredParam} optionalParam={params2.optionalParam}></RouteComponent>
    </Route>
    <Route path="/">
      <RouteComponent requiredParam={params1.requiredParam}></RouteComponent>
    </Route>
  </Route>
</Router>

RouteComponent.svelte

<script>  
  export let requiredParam;
  export let optionalParam= null;
</script>

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

4 participants