1

I have the default page of my webapp which redirects to different components, something like as follows:

<script>
  import page from "page";
  import Form from "./Form.svelte";
  import Dashboard from "./Dashboard.svelte";

  let content = "";
  page.base("/");
  page("", function() {
    content = Form;
  });
  page("dashboard", function() {
    content = Dashboard;
  });
  page({
    hashbang: true
  });
</script>

Now, if I want to pass some props in say, Dashboard page from here, how can I do that? I tried following but it didn't work.

content = new Dashboard({
    props: {
        answer: 42
    }
});
1
  • Can't you use Sapper? Commented Sep 19, 2019 at 11:10

1 Answer 1

2

See the docs for <svelte:component>. To pass down arbitrary props you can use an attribute spread:

<svelte:component this={content} {...props}/>

Here's a live example: https://svelte.dev/repl/74593f36569a4c268d8a6ab277db34b5?version=3.12.1

Here's an official example (currently doesn't demonstrate passing down props): https://svelte.dev/examples#svelte-component

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.