小编ZiZ*_*eng的帖子

将 Next.js 与 typescript 一起使用,但不能在 WithRouterProps 中应用泛型

我使用 VScode 作为 IDE,给出泛型withRouter应该应用于 props.router.query 但不起作用

曾尝试创建组件接口并使用 withRouterProps 扩展,但使用 props.router.query。仍然什么都不显示


    import { withRouter, WithRouterProps } from 'next/router';
    import Layout from '../components/Layout';
    import React from 'react';

    class Page extends React.Component<IPageProps> {
        render() {
            console.log(this.props.router.query.);  <=== should show title in intellience but nothing happened 
            return (
                <Layout>
                    {/* <h1>{this.props}</h1> */}
                    <p>This is the blog post content.</p>
                </Layout>
            );
        }
    }

    export default withRouter(Page);

    interface IPageProps extends WithRouterProps<{ title: string }> {
        test: string;
    }

Run Code Online (Sandbox Code Playgroud)

泛型应该发生。即withRouterProps<{ title: string }>应该使 …

router typescript next.js

6
推荐指数
1
解决办法
678
查看次数

标签 统计

next.js ×1

router ×1

typescript ×1