useRouter/withRouter receive undefined on query in first render

后端 未结 4 891
时光说笑
时光说笑 2021-01-05 15:01

I got a problem with my dynamic route. It look like this

[lang]/abc

I am trying to get query value from [lang] but when I using

4条回答
  •  执念已碎
    2021-01-05 15:44

    I resolved my problem that I need it in Hoc component. I wrapped using withRouter(withLocale(Comp)) and create conditional in HOC

    export default function withLocale(WrappedPage) {
        const WithLocale = ({ router, ...props }) => {
            const { lang } = router.query;
            if (!lang || !isLocale(lang)) {
                return ;
            }
            return (
                
                    
                
            );
        };
       return WithLocale;
    }
    

提交回复
热议问题