Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default layout not processed when using sub folder without a layout #130

Closed
cirolosapio opened this issue Dec 12, 2023 · 7 comments
Closed

Comments

@cirolosapio
Copy link

cirolosapio commented Dec 12, 2023

although a default layout is set when using a sub folder if a layout is not specified in the route tag the default layout is not processed

stackblitz

@JohnCampionJr
Copy link
Owner

I see it. You can work around by putting a file sub.vue in the /src with an empty template.

Have to figure out best way to fix it. Feel free to submit PR if you have an idea

@cirolosapio
Copy link
Author

i have other routes under the sub folder and the issue persist with all of them

i've run in this issue with the version 0.9.0

@markthree
Copy link
Collaborator

markthree commented Dec 13, 2023

although a default layout is set when using a sub folder if a layout is not specified in the route tag the default layout is not processed

stackblitz

@cirolosapio hello, If your application is not particularly complex, you can try using ClientSideLayout, which internally handles this issue

this is example 👉 stackblitz

@hihanley
Copy link

hihanley commented Dec 13, 2023

I see it. You can work around by putting a file sub.vue in the /src with an empty template.

Have to figure out best way to fix it. Feel free to submit PR if you have an idea

@JohnCampionJr
How about this way?
I have same problem, and it is worked for me.

export function setupLayouts(routes) {
  function deepSetupLayout(routes, parentLayout = undefined) {
    return routes.map((route) => {
      // Setup children's layout.
      route.children = deepSetupLayout(route.children ?? [], route.component)

      if (!route.component && route.children.length > 0) {
        // If the route does not have a layout component and contains children, do not setup layout for the route.
        return route
      }
      else {
        // If a layout is specified, use the specified layout.
        // Otherwise, check if the parent layout exists.
        // If the parent layout does not exist, setup default layout.
        return {
          path: route.path,
          component: layouts[route.meta?.layout] || (parentLayout ? undefined : layouts.default),
          children: [{ ...route, path: '' }],
          meta: {
            isLayout: true,
          },
        }
      }
    })
  }

  return deepSetupLayout(routes)
}

@glennmichael123
Copy link

glennmichael123 commented Dec 14, 2023

@cirolosapio I have run into this exact issue as well, any routes that are under a folder don't have default layouts in them. The bandaid fix I did was to add this block of code to every vue file I have.

<route lang="yaml">
meta:
  layout: default
</route>

This now fixes the issue but obviously, this isn't ideal and it would be tedious.

@cirolosapio
Copy link
Author

@cirolosapio hello, If your application is not particularly complex, you can try using ClientSideLayout, which internally handles this issue

this is example 👉 stackblitz

@markthree I saw the new ClientSideLayout but before using it I want to understand what the "limitations" are

@cirolosapio I have run into this exact issue as well, any routes that are under a folder don't have default layouts in them. The bandaid fix I did was to add this block of code to every vue file I have.

<route lang="yaml">
meta:
  layout: default
</route>

This now fixes the issue but obviously, this isn't ideal and it would be tedious.

@glennmichael123 yes i'm using this workaround atm
the default layout is not processed unless specified

@markthree
Copy link
Collaborator

markthree commented Dec 15, 2023

@markthree I saw the new ClientSideLayout but before using it I want to understand what the "limitations" are

@cirolosapio It only supports three options, importMode, defaultLayout, layoutDir, but defaultLayout supports more options,And all options only support simple strings, not arrays or global strings or function,But defaultLayout supports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants