我的版本 9 中有一个名为blog的页面nextjs。
Next为我的页面创建一个路由/博客。现在我想让这些路由映射到同一个博客页面,从而映射到博客组件:
1. /blog/cat1/gold
2. /blog/cat2/silver
3. /blog/cat3/bronze
Run Code Online (Sandbox Code Playgroud)
实际上,我想query parameters在路线中使用它们,但我不想遵循以下格式:
1. /blog?cat=cat1&color=gold
2. /blog?cat=cat2&color=silver
3. /blog?cat=cat3&color=bronze
Run Code Online (Sandbox Code Playgroud)
我使用过,next/router asPath但它完全是客户端,通过重新加载它返回404!
在nextjs 9动态路由中提供了这可能对我有帮助,但问题是我只想拥有一个组件和不同的路由。
你有什么想法?
我有两个 API 路由,我想在其中设置两个 cookie/api/login.js并在/api/logout.js.
这是我的登录 API:
import { serialize } from 'cookie';
export default async (req, res) => {
res.setHeader('Set-Cookie', [
serialize('mytoken1', 'mytoken1Value', {
path: '/',
}),
serialize('mytoken2', 'mytoken2Value', {
path: '/',
}),
]);
res.writeHead(302, { Location: '/' });
res.end();
}
Run Code Online (Sandbox Code Playgroud)
这是我的注销 API:
export default async (req, res) => {
res.removeHeader('Set-Cookie')
res.writeHead(302, { Location: '/api/login' });
res.end();
}
Run Code Online (Sandbox Code Playgroud)
但注销不会删除 cookie,因此当我重新加载页面时,我仍然可以在_app.js ---console.log(req.headers.cookie)--- 中看到它们。您知道在这种情况下如何删除 cookie 吗?
我以这种方式构建我的本机应用程序:
1.npm install expo-cli --global .
2.expo init my-new-project .
3.cd my-new-project and expo start --lan .
4. install expo on my ios device .
5.打开Expo,然后点击“扫描二维码”并在我们的终端中扫描二维码。
但我收到以下错误:
我在两台设备上都连接到相同的 wifi 并且我的 IP 是相同的。我关闭了我的 Windows 防火墙。
你知道为什么会这样吗?我曾经在手机上看到过输出,但此后每次都会出现此错误。
我一直在摆弄gRPC,我正在考虑用 Rust构建我自己的简单而全面的hyperledger织物。SDK
我到处寻找结构gRPC的任何规范hyperledger,看看我们如何重现与对等点交互的功能,例如管理通道以及执行调用和查询之类的功能。
(重现此行为:https://hyperledger-fabric.readthedocs.io/en/release-1.4/commands/peerchannel.html)。
在网上,每个人都说该功能已通过 公开gRPC,但他们建议使用现有的 SDK。
我检查nodeJS SDK并查找了他们的 .proto 文件,但几乎没有任何服务(https://github.com/hyperledger/fabric-sdk-node/tree/release-1.4/fabric-client/lib/protos)
有什么办法可以得到他们的gRPC规格吗?有没有一种通用的方法可以为服务器做到这一点gRPC?为何如此隐藏?
谢谢!
我有一个component包含一个输入的搜索,我定义了一个key up event handler function用于根据输入的字符串获取数据的输入。正如你在下面看到的:
class SearchBox extends Component {
constructor(props) {
super(props);
this.state = {
timeout: 0,
query: "",
response: "",
error: ""
}
this.doneTypingSearch = this.doneTypingSearch.bind(this);
}
doneTypingSearch(evt){
var query = evt.target.value;
if(this.state.timeout) clearTimeout(this.state.timeout);
this.state.timeout = setTimeout(() => {
fetch('https://jsonplaceholder.typicode.com/todos/1/?name=query' , {
method: "GET"
})
.then( response => response.json() )
.then(function(json) {
console.log(json,"successss")
//Object { userId: 1, id: 1, title: "delectus aut autem", completed: false } successss
this.setState({
query: query,
response: json
})
console.log(this.state.query …Run Code Online (Sandbox Code Playgroud) 我有一个旧版本的静态文件夹nextjs。我更新了我nextjs的使用public文件夹。
"next": "^9.4.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
Run Code Online (Sandbox Code Playgroud)
这是我的nextjs配置:
const withPlugins = require('next-compose-plugins');
const withCss = require('@zeit/next-css');
const withSass = require('@zeit/next-sass');
const withImages = require('next-images');
require('dotenv').config();
const withSourceMaps = require('@zeit/next-source-maps')();
if (typeof require !== 'undefined') {
// eslint-disable-next-line no-unused-vars
require.extensions['.css'] = file => {};
}
const nextConfig = {
env: {
BUILD_ENV: process.env.BUILD_ENV,
},
webpack: (config, { isServer }) => {
if (!isServer) {
// eslint-disable-next-line no-param-reassign
config.resolve.alias['@sentry/node'] = '@sentry/browser';
}
if (isServer) …Run Code Online (Sandbox Code Playgroud) assets reactjs server-side-rendering next.js dynamic-routing
这是我的 styledComponent:
\nconst stopPropagation = (event: Event): void => {\n event.stopPropagation();\n};\n\n<StyledComp onClick={stopPropagation}> //error occurs here\n hi StyledComp\n</StyledComp>\nRun Code Online (Sandbox Code Playgroud)\n这就是我的定义:
\nexport type Prop = {\n onClick: (event: Event) => void;\n};\n\nexport const StyledComp = styled.div<Prop>`\n display: flex;\n`;\nRun Code Online (Sandbox Code Playgroud)\n但它返回一个错误,例如:
\n\nTS2769:没有与此调用匹配的重载。\xc2\xa0\xc2\xa0Overload 1 of 2, \'(props: Pick<Pick<Pick<DetailedHTMLProps<HTMLAttributes, HTMLDivElement>, "title" | "slot" | ... 252 更多 ... | "is" > & { ...; } & StyledComp, "标题" | ... 254 个以上 ... | "is"> & Partial<...>, "标题" | ... 254 个以上 …
我正在尝试lazy Loading用于我的应用程序。
索引.js
import React, { Suspense , lazy , Component } from 'react';
import ReactDOM from 'react-dom';
import 'index.scss';
import SomeComponent from './someComponent.js';
import * as serviceWorker from 'serviceWorker';
ReactDOM.render(<SomeComponent />, document.getElementById('root'));
serviceWorker.unregister();
Run Code Online (Sandbox Code Playgroud)
一些组件 index.js 文件
import React, { Suspense , lazy , Component } from 'react';
import { BrowserRouter } from 'react-router-dom';
const Header = lazy(() => import('./_header'));
class SomeComponent extends Component {
render() {
return (
<BrowserRouter>
<React.Fragment>
<Suspense>
<Header />
</Suspense>
</React.Fragment>
</BrowserRouter>
); …Run Code Online (Sandbox Code Playgroud) 我正在使用Wicked PDF,并且在单击按钮时在新选项卡中生成了pdf。但是我想通过单击按钮自动打印pdf 。我添加了这个print_media_type并将值设置为true,我希望我的打印机选项可以开始工作,但是什么也不会发生!有什么想法吗?
respond_to do |format|
format.html
format.pdf do
render pdf: "file_name", :template => 'officials/individual_receipt_export.html.erb', encoding: 'utf8',page_size: 'A4',:print_media_type => true
end
end
Run Code Online (Sandbox Code Playgroud) reactjs ×5
next.js ×3
assets ×1
cookies ×1
expo ×1
express ×1
fetch ×1
flutter ×1
grpc ×1
hyperledger ×1
javascript ×1
lazy-loading ×1
mobile ×1
node.js ×1
react-native ×1
react-router ×1
routing ×1
ruby ×1
setstate ×1
typescript ×1
webpack ×1
wicked-pdf ×1