这是我的 next.js 项目的结构。
我的 404.js 页面是:
'use client';
export default function NotFound() {
return (
<div>
<h2>Not Found</h2>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
当我输入错误的路线时,它不起作用,也不会转到我的自定义页面,而是转到 next.js 404页面。为什么,我哪里错了?
提前致谢。
我想像下面这样在nestjs中禁用X-Powered-By,但它不起作用。
主要.ts:
async function bootstrap() {
const logger = new Logger('bootstrap')
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.disable('X-Powered-By') // this line
...
const PORT = process.env.PORT
await app.listen(PORT);
logger.log(`Application is start on port : ${PORT}`)
}
bootstrap();
Run Code Online (Sandbox Code Playgroud)
禁用X-Powered-By标头后,在下一个请求中,该X-Powered-By标头仍然存在。
我哪里做错了什么?
我在nextjs有一个服务器组件。我想在每次加载此页面时向API发送请求以获取数据。这就是为什么我申请{ cache: 'no-store' }fetch 和 set revalidate to 0,但它不起作用。第一次它向API请求,第二次和第三次......不发送请求。
我认为它从缓存中获取数据。
注意
我添加了import 'server-only'但不影响它。
import 'server-only';
async function getPosts() {
const res = await fetch('http://localhost:4000/posts', { cache: 'no-store' })
return res.json()
}
export const revalidate = 0;
export default async function ServerPage() {
const posts = await getPosts()
return (
<div>
<h2>Server Props...</h2>
<ul>
{posts && posts.map(({ id, title, body }) => {
return (
<li key={id.toString()}>
<strong>{title}-{id}</strong>
<p>{body}</p>
</li>
) …Run Code Online (Sandbox Code Playgroud) 显示地图我使用react-native-maps。我做了所有配置,但是当运行我的项目时,在控制台中收到以下消息:
允许需要循环,但可能导致未初始化的值。考虑重构以消除对循环的需要。需要循环:node_modules\react-native-maps\lib\components\MapView.js -> node_modules\react-native-maps\lib\components\Geojson.js -> node_modules\react-native-maps\lib\components\MapView .js
我认为此消息会导致问题,并且不允许应用程序显示地图。我该如何解决这个问题?
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps'
import React from 'react'
import { View, Text, StyleSheet } from 'react-native'
const App = () => {
return (
<View style={styles.container}>
<MapView
provider={PROVIDER_GOOGLE} // remove if not using Google Maps
style={styles.map}
region={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
</MapView>
</View>
)
}
Run Code Online (Sandbox Code Playgroud) 我想找到一个带有id以下内容的项目:1
const student = await this.db.Student.findByPk(1)
当我得到结果时然后安慰它(console.log(student))
student {
dataValues: { id: 1, name: 'Darush', family: 'Hamidi' },
_previousDataValues: { id: 1, name: 'Darush', family: 'Hamidi' },
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [ 'id', 'name', 'family' ]
},
isNewRecord: false
}
Run Code Online (Sandbox Code Playgroud)
然后将学生发送到浏览器结果将是(res.send(student))?
{
"id": 1,
"name": "Darush",
"family": "Hamidi"
}
Run Code Online (Sandbox Code Playgroud)
为什么我们有差异?