Request: support top-level component props
See original GitHub issueRight now, it seems to be required that you have a single component property called params
on your components to be able to route to them.
For example:
const routes = {
'/:foo/:bar': MyComponent
}
requires a component that declares:
export let params = {};
And accesses the values via params.foo
and params.bar
.
But that makes your component’s design tightly coupled with svelte-spa-router. If I have a component that’s designed to be generally reusable, with parameters like this:
export let foo = "some default foo"
export let bar = "some default bar"
… there doesn’t seem to be a great way to bridge the gap between what is required by svelte-spa-router, and what is expected by general-purpose svelte components.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
React Top-Level API
React.forwardRef accepts a rendering function as an argument. React will call this function with props and ref as two arguments. This function should...
Read more >How to render component again at the top level with the new ...
Ok, I can't call setProps , i had to rerender AddTaskForm component in Todo.js . How can I do this in this case?...
Read more >Top-level await #5501 - sveltejs/svelte - GitHub
I want to have top-level await support for component's <script> that will allow awaiting for promises before component's initialization is ...
Read more >Props! — and how to pass props to components in React ...
Passing only props from component to component doesn't make the component interactive, because nothing is there to change the props. Props are read-only....
Read more >How to use Props in React - Robin Wieruch
Everything you need to know about props in React. How to pass props to components, how to set default props, how to know...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think this should work, although I haven’t tried it! I would just make two suggestions:
export let params = {}
-> Don’t assign default values to that because they will be ignored anywaysfoo
orbar
change (I’ve seen Svelte having some weird behaviors there)If your goal is to have a component work in both svelte-spa-router and standalone, you can also simply consider wrapping your component into another one.
For example, assume you have a component
Foo
that exports proeprtiesfoo
andbar
. Rather than addingFoo
itself to the router (in the route definition object), you create a component calledFooRoute
that contains this:Then you use
FooRoute
in the route definition object.Well, yes. But it depends on how many components you need wrapped too!