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

was created with unknown prop 'location' #122

Closed
ligrant opened this issue Mar 21, 2020 · 15 comments
Closed

was created with unknown prop 'location' #122

ligrant opened this issue Mar 21, 2020 · 15 comments

Comments

@ligrant
Copy link

ligrant commented Mar 21, 2020

If use:
<Route exact path="about"><About /></Route>
All good.
If use:
<Route exact path="about" component={About} />
About.svelte:14 was created with unknown prop 'location'
About.svelte:14 was created with unknown prop 'exact'

Any ideal?

"svelte": "^3.20.1"
"svelte-routing": "^1.4.2"

@n0n3br
Copy link

n0n3br commented Mar 21, 2020

Can you put the app in repl or codesandbox so we can reproduce the error and try fo fix it ?

@ligrant
Copy link
Author

ligrant commented Mar 22, 2020

Basically I just follow the instruction created a svelte app and install the svelte-routing lib, and copy past.
Today I tried recreate the app on sandbox, it's working well. don't know why i got the warning when running on localhost!

maybe just leave it alone or use <Route exact path="about"><About /></Route> instead
Any suggest will be appreciated

### localhost
Screen Shot 2020-03-23 at 12 39 18 am

### sandbox
Screen Shot 2020-03-23 at 12 39 33 am

@GarethOates
Copy link

GarethOates commented Apr 5, 2020

I get this warning if I do:
<Route path="post" component="{Post}" />
but not when I do
<Route path="post"><Post /></Route>

@BogdanDarius
Copy link

In the About component add:
export let location;

@EmilTholin
Copy link
Owner

Hi @ligrant!

You get this warning because the location prop is passed to the rendered component in the Route:

<svelte:component this="{component}" location={$location} {...routeParams} {...routeProps}  />

This is so that you can make use of the location information in your component:

<!-- App.svelte -->
<Route path="blog" component="{Blog}" />

<!-- Blog.svelte -->
<script>
  import queryString from "query-string";

  export let location;

  let queryParams;
  $: queryParams = queryString.parse(location.search);
</script>

<h1>Blog</h1>
<p>{queryParams.foo}</p>

This sadly means that you get a warning if you are not using the passed in location prop in your component. I'm not sure how to make this warning go away without making the API more cumbersome.

The exact prop should however not be passed to the rendered component, so About.svelte:14 was created with unknown prop 'exact' is a bug that we will fix.

@clintwood
Copy link

clintwood commented May 20, 2020

@EmilTholin I obviously have the same issue but was thinking that since the location prop is not always used by components would it not make sense to rather expose make it available via context/store (IIRC there is getContext(LOCATION) or some store).

I'm not super familiar with svelte-routing internals but something like:

<!-- Blog.svelte -->
<script>
  import { location } from 'svelte-routing';
  import queryString from "query-string";

  let queryParams;
  $: queryParams = queryString.parse($location.search);
</script>

<h1>Blog</h1>
<p>{queryParams.foo}</p>

EDIT: Interestingly I've just seen that svelte-spa-router does as I'm suggesting for both $location and $querystring.

@jimmywarting
Copy link

PS use URLSearchParams instead of query-string

@quantuminformation
Copy link

quantuminformation commented Jul 1, 2020

Also getting this here

https://github.com/quantuminformation/svelte-firebase-starter

  <Route path="register" component="{Register}" />
            <Route path="recover" component="{Recover}" />
            <Route path="signin" component="{Signin}" />
            <Route path="settings" component="{Settings}" />
            <Route path="users" component="{Users}" />
            <Route path=":username" component="{Profile}" />

            <Route path="/" component="{Home}" />

image

@HNazmul-X
Copy link

I got the same error at the console... My code is also similar this that is

<Route  path="/" component={Homepage} />
<Route path="/add-poll/" component={About} />

Screenshot_84

@HNazmul-X
Copy link

hey, @EmilTholin this package becoming popular. you should fix all of the bugs. I saw that the latest version is a year ago. please fix the bug

@talwat
Copy link

talwat commented Jun 18, 2022

I'm having the same exact issue.

@ainaarawaida
Copy link

was created with unknown prop 'location'
was created with unknown prop 'navigate'

same error here when use
<Route
path={mylinkurl + "my-account/tambahJenisYuran"}
component={TambahJenisYuran}
/>

@mkmoisen
Copy link

@EmilTholin What is the solution to this problem?

If we don't use export let location; the console debugger shows a warning.

If we do use export let location; the IDE shows a warning for unused variable.

This works in some cases:

<Route path="/"><Home /></Route>

But it does not work when you have parameters:

<Route path="/*foo"><Home /></Route>

Property 'foo' is missing in type '{}' but required in type '{ foo: any; }'.js(2741)

@krishnaTORQUE
Copy link
Collaborator

Hi
I forked svelte-routing > https://github.com/krishnaTORQUE/svelte-routing-next.
I resolved this issue there.
And I merged most of the PR from origin repo.
Please let me know if you have any query.
Thanks.

@krishnaTORQUE
Copy link
Collaborator

Svelte Routing v1.8.0 released.
This issue has been fixed.
View Changelog: https://github.com/EmilTholin/svelte-routing/blob/master/CHANGELOG.md

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