首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >接下来,js不会在生成中加载动态页。

问接下来,js不会在生成中加载动态页。
EN

Stack Overflow用户
提问于 2022-11-03 14:52:39
回答 1查看 122关注 0票数 1

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

下面是我的代码:在__app.js中

代码语言:javascript
复制
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> }
}

下面是我的下一个配置:

代码语言:javascript
复制
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能够在访问时运行。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-09 13:17:49

这个问题似乎与文件夹结构无关。

但是,在下一个配置中,它很可能与target: 'serverless'相关,因为netfly docs -> suggested configuration values提到:

无服务器目标 在接下来的12个中,不推荐使用无服务器和实验性的无服务器跟踪目标,所有使用Next.js运行时构建的都使用默认的服务器目标。如果您以前在next.config.js中设置了目标,则应该删除它。

(所以您应该从下一个配置中删除target: 'serverless' )

您还可以查看这个答案和这个答案,了解为什么一般不推荐serverless (非常特殊的情况除外)的更多信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74305078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档