javascriptsveltesvelte-componentroutify

Routify - what directory to place components that are not intended as routes?


Basic question here.

In Routify, anything in the top level of the pages directory is rendered with an endpoint that matches the page name.

Ok - got it!

However, if I want to create a component that is not intended as an endpoint and is only intended to be imported into another page that is a route, what directory structure do I use?

More generally, what do I need to know to do this? Best practices ?

Thank you!


Solution

  • You would simply place them in a directory adjacent to pages and then you do something like import MyComponent from '../../components/MyComponent.svelte (with the correct number of ..)

    - src
       - components
       - pages
    

    As a bonus, if you call the folder node_modules instead like this

    - src
       - node_modules
       - pages
    

    you can just do import Mycomponent from 'MyComponent.svelte' but this is a way that not everyone likes.