How to have multiple routes for retrieving same html content

85 Views Asked by At

I have 2 routes /main and /home. Both should show the same HTML content. Is it possible to point both the routes to the same hbs file?

2

There are 2 best solutions below

0
NullVoxPopuli On

It's not possible to point routes at the same hbs file, but this is what components are for

First, generating a component can be done via ember g component my-content

then in app/routes/main.hbs You could define:

<MyContent />

and then in app/routes/home.hbs You could define:

<MyContent />
0
Ankush Dharkar On

I second the suggestion by @NullVoxPopuli. (Only adding this because I can't seem to add Markdown in the comments for the answer above).

app/
┣ components/
┃ ┗ my-content.hbs (the common HTML content)
┣ routes/
┃ ┣ home.ts
┃ ┗ main.js
┣ templates/
┃ ┣ home.hbs
┃ ┣ main.hbs
┣ ...

Components make your code highly reusable.