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

props cannot be passed - or can they? #139

Open
flipkickmedia opened this issue Dec 18, 2022 · 1 comment
Open

props cannot be passed - or can they? #139

flipkickmedia opened this issue Dec 18, 2022 · 1 comment

Comments

@flipkickmedia
Copy link

flipkickmedia commented Dec 18, 2022

Hi svelte-router-spa peoples.

I'm trying to build a dynamic component system and am using svelte-router-spa as the core of the routing.

#9

I see this isn't currently supported.

In order for this system to work effectively I'm unable to use stores or context because I don't know until Ive loaded the component, what the requirements for that component is.

Aside from my use, this breaks the component flow inside svelte. It's kinda cumbersome to require the components to implement stores or context to retrieve data when there is a mechanism already in place.

I did make some progress passing props to the Layout using this as a basis - https://svelte.dev/repl/74593f36569a4c268d8a6ab277db34b5

let layoutProps = () => {
  component = Layout;
  props = {
    path: `${path}/${label}/${name}`,
    name: `layout`,
  };
};

let routes = [
    {
      name: "/people",
      component: HorizontalSplitView,
      layout: layoutProps(),
      currentRoute: "",
    },
  ];

When I try this with the component e.g.

let horizontalSplitViewProps = () => {
  component = HorizontalSplitView;
  props = {
    path: `${path}/${label}/${name}`,
    name: `hsplit`,
  };
};

let layoutProps = () => {
  component = Layout;
  props = {
    path: `${path}/${label}/${name}`,
    name: `layout`,
  };
};

let routes = [
    {
      name: "/people",
      component: horizontalSplitViewProps(),
      layout: layoutProps()
    },
  ];

I don't see any errors but the route doesn't load :(

Would you accept a PR for this so you can pass this form of component? It works for layout so it seems sensible for it to work for component

Keep working on this lib, its probably the most flexible svelte router and the only one which works with this type of dynamic config. Great work :)

@flipkickmedia
Copy link
Author

I've done the work for this and forked this repo as this is no longer being maintained.

https://github.com/flipkickmedia/svelte-router-spa

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

1 participant