vue.js - How to Handle Multiple Template Layouts Based on Domain in a Vue (Vite) App? - Stack Overflow

I’m working on a Vue app (using Vite) that has three different template layouts, and the layout should

I’m working on a Vue app (using Vite) that has three different template layouts, and the layout should be determined by the domain the user visits.

Requirements:

  • If a user visits test1, they should see Template 1.
  • If a user visits test2, they should see Template 2.
  • If a user visits test3, they should see Template 3.
  • Most of the components and logic are shared, but each template has some unique styles and components.
  • The app does not use SSR.
  • Users cannot switch templates within the app (the template is fixed per domain). The project has a shared folder with common store, router, and shared components.

What I’ve Tried: I attempted to fetch the template ID and pass it into vite.config.js, but I think the issue is that this approach needs to be handled at build time or runtime.

My Question:

  • What is the best way to set up this kind of multi-template structure, without making users download unnecessary components?
  • Should I be handling this at build time (e.g., different builds for each template) or at runtime (e.g., dynamically loading only relevant files)?
  • What’s the best way to configure Vite to handle this cleanly?

Any guidance or best practices would be appreciated!

I’m working on a Vue app (using Vite) that has three different template layouts, and the layout should be determined by the domain the user visits.

Requirements:

  • If a user visits test1, they should see Template 1.
  • If a user visits test2, they should see Template 2.
  • If a user visits test3, they should see Template 3.
  • Most of the components and logic are shared, but each template has some unique styles and components.
  • The app does not use SSR.
  • Users cannot switch templates within the app (the template is fixed per domain). The project has a shared folder with common store, router, and shared components.

What I’ve Tried: I attempted to fetch the template ID and pass it into vite.config.js, but I think the issue is that this approach needs to be handled at build time or runtime.

My Question:

  • What is the best way to set up this kind of multi-template structure, without making users download unnecessary components?
  • Should I be handling this at build time (e.g., different builds for each template) or at runtime (e.g., dynamically loading only relevant files)?
  • What’s the best way to configure Vite to handle this cleanly?

Any guidance or best practices would be appreciated!

Share Improve this question edited Mar 21 at 7:04 Kamran Khalid 1 asked Mar 3 at 4:41 Hamzah HameedHamzah Hameed 1 1
  • 1 The question is too broad for SO at this point. It's unknown what "layout" is in your case. Is it one component or what? This can be achieved with any form of dependency injection. You can pass "layout" through App component props or slots, through provide/inject, or through appponent(). On Vite level you can remap imports with "alias" config – Estus Flask Commented Mar 3 at 9:09
Add a comment  | 

1 Answer 1

Reset to default -1

Are you familiar with vue-router? It allows you to map routes to components, supports nested routing where you can create multiple top-level routes to establish base layouts. The documentation can be found here: vue-router

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745109527a4611763.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信