Questions tagged «next.js»

1
TypeError:无法读取未定义的属性“ webpackJsonp”
我有一个大约2年前使用create-react-app创建的react应用(应用A),它已弹出。该应用程序已导出为commonjs2模块,并以NPM软件包的形式提供,以供next.js项目(应用程序B)使用。 一切都进行得很顺利,直到我更新了应用程序A中的某些程序包,其中包含一些我们使用的通用组件。导入应用B时的错误是未定义窗口,可能是由于SSR所致。 我通过使用在应用A的webpack配置中解决了此问题globalObject: 'this'。 现在,当我尝试在应用B中导入应用A时,错误消息为: TypeError: Cannot read property 'webpackJsonp' of undefined 我认为某处正在尝试致电window['webpackJsonp']? 我已经尝试过更改webpackJsonpFunction,但是正如预期的那样,它将仅尝试获取undefined的其他属性。 任何帮助将不胜感激! 全栈跟踪: [ error ] TypeError: Cannot read property 'webpackJsonp' of undefined at /Users/syberen/projects/parentcompany/pblx-store-detail/build/static/js/main.js:1:2087 at Object.<anonymous> (/Users/syberen/projects/parentcompany/pblx-store-detail/build/static/js/main.js:1:2203) at Module._compile (internal/modules/cjs/loader.js:776:30) at Module.m._compile (/Users/syberen/projects/parentcompany/companyname/node_modules/ts-node/src/index.ts:473:23) at Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Object.require.extensions.<computed> [as .js] (/Users/syberen/projects/parentcompany/companyname/node_modules/ts-node/src/index.ts:476:12) at Module.load (internal/modules/cjs/loader.js:643:32) at Function.Module._load …
16 reactjs  npm  webpack  next.js 

6
Next.js从/重定向到另一个页面
我是Next.js的新手,并且想知道如何从起始页(/)重定向到/ hello-nextjs。用户加载页面后,确定路径是否=== /重定向至/ hello-nextjs 在react-router中,我们执行以下操作: <Switch> <Route path="/hello-nextjs" exact component={HelloNextjs} /> <Redirect to="/hello-nextjs" /> // or <Route path="/" exact render={() => <Redirect to="/hello-nextjs" />} /> </Switch>

1
使用Typescript使用getInitialProps将prop传递到Next.js中的每个页面
我遇到一种情况,我需要在页面呈现到服务器端并使用Next.js发送回我之前,先了解用户是否已登录,以避免UI中出现闪烁变化。 我能够弄清楚如果用户已经使用此HOC组件登录,如何防止用户访问某些页面... export const noAuthenticatedAllowed = (WrappedComponent: NextPage) => { const Wrapper = (props: any) => { return <WrappedComponent {...props} />; }; Wrapper.getInitialProps = async (ctx: NextPageContext) => { let context = {}; const { AppToken } = nextCookie(ctx); if (AppToken) { const decodedToken: MetadataObj = jwt_decode(AppToken); const isExpired = …

1
响应标头中的网络X内容编码,而不是内容编码
我正在尝试使用Nginx和NodeJS服务器的Gzip传递压缩用Next.js编写的代码。 当我用于curl -H "Content-Encoding: gzip"验证时,似乎配置正在工作。 但是来到真正的浏览器(Chrome,Firefox)时,我无法Content-Encoding: gzip在Response Headers中找到该属性。 代替,X-Content-Encoding-Over-Network: gzip出现了。 我使用Google Lighthouse测试了该网站,但它责备我对文本文件启用压缩功能。 其实是什么X-Content-Encoding-Over-Network意思? 我该如何使用gzip? Nginx设置: gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.0; gzip_types text/css text/plain text/javascript application/javascript application/json application/x-javascript application/xml application/xml+rss application/xhtml+xml application/x-font-ttf application/x-font-opentype application/vnd.ms-fontobject image/svg+xml image/x-icon application/rss+xml application/atom_xml; Next.js设置 // next.config.js …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.