简体   繁体   English

Routify - 放置不打算用作路由的组件的目录是什么?

[英]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.在 Routify 中,页面目录顶层中的任何内容都使用与页面名称匹配的端点呈现。

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!谢谢!

Components and folders prefixed with an underscore are ignored by Routify when it creates the routes for your app. Routify 在为您的应用创建路由时会忽略以下划线为前缀的组件和文件夹。

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.因此,您可以调用您的组件_MyComponent.svelte并将其保存在同一目录中,或者拥有一个_components子目录并将其保存在那里,您可以随意命名。

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..)您只需将它们放在与pages相邻的目录中,然后执行import MyComponent from '../../components/MyComponent.svelte (使用正确数量的..)

- src
   - components
   - pages

As a bonus, if you call the folder node_modules instead like this作为奖励,如果您像这样调用文件夹node_modules

- src
   - node_modules
   - pages

you can just do import Mycomponent from 'MyComponent.svelte' but this is a way that not everyone likes.您可以只import Mycomponent from 'MyComponent.svelte'但这种方式并非所有人都喜欢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM