I can't create multiple layout.tsx files. It doesnt work for it
Answered
Blue swimming crab posted this in #help-forum
Blue swimming crabOP
app/login/layout.tsx
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div className="flex-grow p-6 md:overflow-y-auto md:p-12">
{children}
</div>
);
}
app/login/page.tsx
"use client";
import React from "react";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { cn } from "@/utils/cn";
import Layout from "./layout";
export default function LoginPage() {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
console.log("Form submitted");
};
return (
<Layout>
<h1>hi</h1>
</Layout>
)
}
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div className="flex-grow p-6 md:overflow-y-auto md:p-12">
{children}
</div>
);
}
app/login/page.tsx
"use client";
import React from "react";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { cn } from "@/utils/cn";
import Layout from "./layout";
export default function LoginPage() {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
console.log("Form submitted");
};
return (
<Layout>
<h1>hi</h1>
</Layout>
)
}
23 Replies
Blue swimming crabOP
title says the problem.
why do you have a layout inside your page?
<Layout>
<h1>hi</h1>
</Layout>
<Layout>
<h1>hi</h1>
</Layout>
Blue swimming crabOP
bc it didnt work
do i had to try smth
and it doesnt remove the root layout.tsx
alright. Remove that. Your layout will wrap your page with the stuff that you want. So put your layout inside your layout.js and put your page stuff inside your page.js
Blue swimming crabOP
i did
but now its still loading the root layout
is there a way to remove that
@Blue swimming crab is there a way to remove that
yes, you can use route groups, to define either [multiple root layouts](https://nextjs.org/docs/app/building-your-application/routing/route-groups#creating-multiple-root-layouts) or just organize your routes and layouts with [route groups](https://nextjs.org/docs/app/building-your-application/routing/route-groups)
Blue swimming crabOP
i set it up
but still got the root layout
or do i need to make for the home page etc also a group
Answer
Blue swimming crabOP
then its complaining that i dont have a 'root layout'
If you using this case, you need to include in both layouts the html and body-tag
you can also create a root layout (only html and body) and use seperate layouts in your route groups
Blue swimming crabOP
ah okay
1 question how to make the / page
cuz i have to wrap it in (home)
is it just app/(home)/page.tsx?
yes. Where do you want to put it and then put it there