router doesn't work
Unanswered
Reddish carpenter ant posted this in #help-forum
Reddish carpenter antOP
router doesnt work i just get 404 no matter what i do
126 Replies
Reddish carpenter antOP
import {AppProps} from "next/app"
import Layout from "../components/layout"
export default function App({Component, pageProps}: AppProps) {
return (
<Layout>
<Component {...pageProps} />
</Layout>
)
}pages/_app.tsxi have
pages/index.tsx component for rootit just doesnt work
thers also a
app/layout.tsx fileidk what else to tell you
there also a page
pages/Content.tsxeverything default exports a component
pages/index.tsxexport default function Page() {
return null
}@Reddish carpenter ant i have `pages/index.tsx` component for root
do you mean you go to
http://localhost:3000 and got 404?Reddish carpenter antOP
yep
the vercel 404
even if i go to
/content ill get a 404@Reddish carpenter ant yep
export default function Page() {
return <div>hello</div>
}have you tried this?
@Reddish carpenter ant even if i go to `/content` ill get a 404
how about
/Content?Reddish carpenter antOP
yep
nothing works
could you show the folder structure
in a screenshot
Reddish carpenter antOP
@Reddish carpenter ant Click to see attachment
move
pages folder to rootsame level as
app folderReddish carpenter antOP
whats the point of the app folder then
and docs say otherwise
@Reddish carpenter ant whats the point of the app folder then
its for app router
Reddish carpenter antOP
can i also move assets and components to repo root?
yes
but don't move it inside
pages because every file inside pages will become a routeReddish carpenter antOP
intellisense broke
the @ import broke
import {LayoutProps} from "@/.next/types/app/layout"well your editor changed the path for you
Reddish carpenter antOP
"paths": {
"@/*": ["./*"]
},what is this
why does this exist
it says cannot find
find what?
Reddish carpenter antOP
Cannot find module '@/.next/types/app/layout' or its corresponding type declarations.ts(2307)Reddish carpenter antOP
repo root
inside components dir
so
import {LayoutProps} from "./components/layout"Reddish carpenter antOP
no this line is inside components/layout
import {LayoutProps} from "./.next/types/app/layoutReddish carpenter antOP
no
had to add
"baseUrl": "." to tsconfigwhy doesn't create next app do this
wait it still doesnt work
?
Reddish carpenter antOP
Cannot find module '@/app/bloom' or its corresponding type declarations.ts(2307)change the import path
Reddish carpenter antOP
change the what
to what
where is the bloom folder
Reddish carpenter antOP
in
@/app/bloomits not a folder
Reddish carpenter antOP
it still doesnt work
now it only doesnt work for .next imports
Reddish carpenter antOP
what should be the type then?
@Reddish carpenter ant what should be the type then?
what are you gonna pass it?
Reddish carpenter antOP
idk
the docs told me to make this file
ok now routes are working
but the root layout file from
app/layout.tsx does nothing nowjust children props then
because you are viewing a route in
pages routerReddish carpenter antOP
how do i make it work then
should i return html from my
components/layout.tsximport type {Metadata} from "next"
import {Urbanist} from "next/font/google"
import "./main.scss"
const urbanist = Urbanist({subsets: ["latin"]})
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
}
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode
}>) {
return (
<html lang="en">
<head>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200"
/>
</head>
<body className={urbanist.className}>{children}</body>
</html>
)
}like this?
check the example in doc
https://nextjs.org/docs/pages/building-your-application/routing/pages-and-layouts#layout-pattern
https://nextjs.org/docs/pages/building-your-application/routing/pages-and-layouts#layout-pattern
Reddish carpenter antOP
how do i add the className to body then?
and head tag
Reddish carpenter antOP
Reddish carpenter antOP
what
import "@/app/main.scss"
import {Html, Main, NextScript} from "next/document"
import Head from "next/head"
export default function Document() {
return (
<Html lang="en">
<Head>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}import styles in _app.js intead
Reddish carpenter antOP
im not
where style
Reddish carpenter antOP
my css isnt working
can i use @ in scss?
there are no errors
it just doesnt apply
did you import the style
Reddish carpenter antOP
yes
on where
Reddish carpenter antOP
_app
there is literally nothing in the head tag
@Reddish carpenter ant tsx
import "@/app/main.scss"
import {Html, Main, NextScript} from "next/document"
import Head from "next/head"
export default function Document() {
return (
<Html lang="en">
<Head>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
yes because you didn't render the
<Head /> from next/documentI would suggest you create a new project with
npx create-next-app@latest and choose not to use app routerReddish carpenter antOP
what
i used
npx create-next-app@latestwhat is app router
the route inside the
app folderReddish carpenter antOP
is this deprecated already?
I don't understand why did you create the project with app router then migrate to page router
no
Reddish carpenter antOP
it didnt even tell me
that im not suppsed to use it
if you want to use page router, just choose not to use app router
Reddish carpenter antOP
i still dont know what app router is
https://nextjs.org/docs
you should check the doc
you should check the doc
Reddish carpenter antOP
i did
its not there
@Reddish carpenter ant its not there
which mean you didn't read
Reddish carpenter antOP
i did
i didnt see this dropdown
i didnt even know it existed
i was stuck on pages router
thanks for your help
how to get the current route?
without using a client component and usePathname?
how to make routes case-insensitive?
or convert file name to kebab case