我有两条路线/主路线和/主路线。两者应显示相同的HTML内容。是否可以将两个路由指向同一个hbs文件?
eiee3dmh1#
不可能将路由指向同一hbs文件,但这是组件的用途🎉首先,可以通过ember g component my-content生成组件然后在app/routes/main.hbs中,您可以定义:
ember g component my-content
app/routes/main.hbs
<MyContent />
然后在app/routes/home.hbs中,您可以定义:
app/routes/home.hbs
knsnq2tg2#
我支持@NullVoxPopuli的建议。(只是添加了这个,因为我似乎无法在上面的答案注解中添加Markdown)。
app/┣ components/┃ ┗ my-content.hbs (the common HTML content)┣ routes/┃ ┣ home.ts┃ ┗ main.js┣ templates/┃ ┣ home.hbs┃ ┣ main.hbs┣ ...
app/
┣ components/
┃ ┗ my-content.hbs (the common HTML content)
┣ routes/
┃ ┣ home.ts
┃ ┗ main.js
┣ templates/
┃ ┣ home.hbs
┃ ┣ main.hbs
┣ ...
组件使代码具有高度的可重用性。
2条答案
按热度按时间eiee3dmh1#
不可能将路由指向同一hbs文件,但这是组件的用途🎉
首先,可以通过
ember g component my-content
生成组件然后在
app/routes/main.hbs
中,您可以定义:然后在
app/routes/home.hbs
中,您可以定义:knsnq2tg2#
我支持@NullVoxPopuli的建议。(只是添加了这个,因为我似乎无法在上面的答案注解中添加Markdown)。
组件使代码具有高度的可重用性。