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

again: <component> was created with unknown prop 'params' #98

Closed
dm-de opened this issue Apr 2, 2020 · 10 comments
Closed

again: <component> was created with unknown prop 'params' #98

dm-de opened this issue Apr 2, 2020 · 10 comments
Labels
wontfix This will not be worked on

Comments

@dm-de
Copy link

dm-de commented Apr 2, 2020

It seems that this bug is not fully fixed:
#83

404-Components still have this issue for me

import NotFound from '../views/404.svelte'
const routes = {
	...
	'*': NotFound, //<<<<<<<
}
...
@ItalyPaleAle
Copy link
Owner

This is a good point but it's not something I can fix.

First, please note that it's just a warning that Svelte (not the router) emits, so: it won't break your app, and it's not something we can disable.

The fix for #83 consisted in passing the params prop only if there's a match in the path. That is, if your path is a fixed one (such as /hello/world) then there's nothing matched, so the router doesn't pass anything to the route. If there's anything that would create a match, then it's passed.

In the case of the * route, the router does create a params.wild prop, which matches the page that wasn't found. And that's passed to the component.

There's not much we can do there. It's not possible for a Svelte component to inspect another Svelte component and check if it exposes any prop (that is only possible if Svelte components are compiled as "custom elements" per https://svelte.dev/docs#Custom_element_API ).

You can only adopt a workaround, which can be one of:

  1. Ignore the warning, given that it's just a warning anyways. It's annoying, but it won't break your app
  2. In your NotFound component, expose the params prop: export let params = {}. You don't need to use that prop at all, but it being there will disable the warning.

I understand this is not ideal, but sadly this is not something we can change as it's how Svelte works.

@ItalyPaleAle ItalyPaleAle added the wontfix This will not be worked on label Apr 2, 2020
@frederikhors
Copy link
Contributor

This is very annoying and I think there must be a better solution.

@ItalyPaleAle
Copy link
Owner

@frederikhors I'm happy to accept PRs :)

@frederikhors
Copy link
Contributor

@frederikhors I'm happy to accept PRs :)

I wish I was capable of.

@frederikhors
Copy link
Contributor

I opened this: sveltejs/svelte#4652.

We'll see.

@ItalyPaleAle
Copy link
Owner

Thank you! I had opened another issue too asking for an API, but your approach seems better :)

@frederikhors
Copy link
Contributor

What is your issue? Can you link here?

@frederikhors
Copy link
Contributor

I <3 you and your router!

@ItalyPaleAle
Copy link
Owner

sveltejs/svelte#4649

Thank you! :)

@joshnwosu
Copy link

Adding export let params = {} did not remove the warning for me.

This fixed the warning I was getting.

<script>
    export let params = {}
</script>
<main>
    <h1>{params && 'Page Not Found'}</h1>
</main>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants