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

706 views Asked by At

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!

2

There are 2 answers

0
Stephane Vanraes On BEST ANSWER

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.

0
shedside On

Components and folders prefixed with an underscore are ignored by Routify when it creates the routes for your app.

So, you could call your component _MyComponent.svelte and keep it in the same directory, or have a _components subdirectory and keep it there, named however you wish.