小编Yas*_*idi的帖子

History.push a link to a new tab with react router

执行一些逻辑后,我需要打开一个指向新选项卡的链接。
我有一个这样的按钮:

<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()

reactjs react-router react-router-dom

16
推荐指数
1
解决办法
1万
查看次数

如何通过 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

这是 [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
\n\n

我只是不知道如何type向路由器提供参数。

\n

reactjs next.js

9
推荐指数
1
解决办法
1万
查看次数

我如何在 typeorm 和 postgres 中使用经度和纬度

我当前的实体如下所示:

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。

postgresql typeorm nestjs

8
推荐指数
2
解决办法
3640
查看次数

如何创建动态角色防护,以在控制器和处理程序中工作

我定义一个角色守卫是这样的:

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)

nestjs nestjs-passport

4
推荐指数
1
解决办法
4057
查看次数