执行一些逻辑后,我需要打开一个指向新选项卡的链接。
我有一个这样的按钮:
<Button
onClick={handleSubmit}
>
Preview
</Button>
Run Code Online (Sandbox Code Playgroud)
与 handleSubmit() 是:
<Button
onClick={handleSubmit}
>
Preview
</Button>
Run Code Online (Sandbox Code Playgroud)
如您所见,对于我的用例,使用该Link
组件是没有意义的。
那么,有没有办法将该链接推送到新选项卡,只使用 history.push()
这是我的页面树
\n\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 _app.tsx\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 _document.tsx\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.tsx\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 [type]\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 [slug].tsx\n
Run Code Online (Sandbox Code Playgroud)\n\n这是 [slug] 页面的 getStaticPaths:
\n\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 _app.tsx\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 _document.tsx\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.tsx\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 [type]\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 [slug].tsx\n
Run Code Online (Sandbox Code Playgroud)\n\n例如,页面看起来像这样\nhttp://localhost:3000/programming/some-slug
当我转到某个帖子时,我收到此错误:
\n\n\n\n\n未在 getStaticPaths 中为 /[type]/[slug] 提供所需参数(类型)作为字符串
\n
我只是不知道如何type
向路由器提供参数。
我当前的实体如下所示:
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Landmark extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
longitude: number
@Column()
latitude: number
}
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有更好的方法来做到这一点,使用一种特殊的 postgres 类型,它适用于 typeorm。
我定义一个角色守卫是这样的:
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { Observable } from 'rxjs';
import { User } from './user.entity';
@Injectable()
export class RolesGuard implements CanActivate {
constructor(
private reflector: Reflector,
) { }
async matchRoles(roles: string[], userRole: User["roles"]) {
let match = false;
if (roles.indexOf(userRole) > -1) {
match = true;
}
return match
}
canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
const roles = this.reflector.get<string[]>('roles', context.getClass());
if (!roles) …
Run Code Online (Sandbox Code Playgroud)