我有一个使用动态路径的下一个js应用程序。动态路由在dev模式下工作得很好,但是当我构建它并将它发送到netlify时,它们会抛出404。

下面是我的代码:在__app.js中
import { useEffect } from 'react';
import Router from 'next/router';
import { useRouter } from 'next/router'
import { initGA, logPageView } from 'analytics';
import 'rc-drawer/assets/index.css';
import 'rc-tabs/assets/index.css';
import 'swiper/swiper-bundle.css';
import 'react-toastify/dist/ReactToastify.css';
import { MantineProvider } from '@mantine/core';
import { NotificationsProvider } from '@mantine/notifications';
export default function CustomApp({ Component, pageProps }) {
const router = useRouter()
useEffect(() => {
initGA();
logPageView();
Router.events.on('routeChangeComplete', logPageView);
}, []);
if(router == '/') {return <Component {...pageProps} />;}
else {return <MantineProvider withGlobalStyles withNormalizeCSS> <NotificationsProvider> <Component {...pageProps} /></NotificationsProvider></MantineProvider> }
}下面是我的下一个配置:
const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');
const nextConfiguration = {
target: 'serverless', //will output independent pages that don't require a monolithic server. It's only compatible with next start or Serverless deployment platforms (like ZEIT Now) — you cannot use the custom server API.
};
module.exports = withPlugins([optimizedImages], nextConfiguration);我需要的是calendar.jsx能够在访问时运行。
发布于 2022-11-09 13:17:49
这个问题似乎与文件夹结构无关。
但是,在下一个配置中,它很可能与target: 'serverless'相关,因为netfly docs -> suggested configuration values提到:
无服务器目标 在接下来的12个中,不推荐使用无服务器和实验性的无服务器跟踪目标,所有使用Next.js运行时构建的都使用默认的服务器目标。如果您以前在next.config.js中设置了目标,则应该删除它。
(所以您应该从下一个配置中删除target: 'serverless' )
https://stackoverflow.com/questions/74305078
复制相似问题