質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

解決済

2回答

4804閲覧

react routerエラー

satodesu

総合スコア38

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2020/04/09 02:39

編集2020/04/09 02:43

reactRouterを使っているとこで下記のエラーが出てしまいます。
解決方法わかる人がいましたらご教授お願いしたいです。

No overload matches this call. Overload 1 of 2, '(props: Readonly<RouteProps>): Route<RouteProps>', gave the following error. 型 'Element' を型 'ComponentClass<any, any> | FunctionComponent<any> | ComponentClass<RouteComponentProps<any, StaticContext, any>, any> | FunctionComponent<RouteComponentProps<any, StaticContext, any>>' に割り当てることはできません。 型 'Element' を型 'FunctionComponent<RouteComponentProps<any, StaticContext, any>>' に割り当てることはできません。 型 'Element' にはシグネチャ '(props: PropsWithChildren<RouteComponentProps<any, StaticContext, any>>, context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<...>)>' に一致するものがありません。 Overload 2 of 2, '(props: RouteProps, context?: any): Route<RouteProps>', gave the following error. 型 'Element' を型 'ComponentClass<any, any> | FunctionComponent<any> | ComponentClass<RouteComponentProps<any, StaticContext, any>, any> | FunctionComponent<RouteComponentProps<any, StaticContext, any>>' に割り当てることはできません。 型 'Element' を型 'FunctionComponent<RouteComponentProps<any, StaticContext, any>>' に割り当てることはできません。ts(2769) index.d.ts(87, 3): The expected type comes from property 'component' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Route<RouteProps>> & Readonly<RouteProps> & Readonly<{ children?: ReactNode; }>' index.d.ts(87, 3): The expected type comes from property 'component' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Route<RouteProps>> & Readonly<RouteProps> & Readonly<{ children?: ReactNode; }>'
<Route exact path={`${BaseUrl}/${Paths.user}`}   // ここでエラーが出る component={ <UserCreate CountText={props.minimumLength} isUser={props.isuser} isUppeCase={props.isuppercase} isSymbolCase={props.isymbolcase} /> } />

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

<Route exact path={`${BaseUrl}/${Paths.user}`} component{() => <UserCreate CountText={props.minimumLength} isUser={props.isuser} isUppeCase={props.isuppercase} isSymbolCase={props.isymbolcase} /> </Route>

としたら解決しました

投稿2020/04/09 05:34

satodesu

総合スコア38

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

Route の component 属性にはコンポーネントの名前 (つまり UserCreate だけ) しか書けません。
<UserCreate CountText=... /> を書きたければ、次のように子要素にすると良いでしょう。

<Route exact path={`${BaseUrl}/${Paths.user}`}> <UserCreate CountText={props.minimumLength} isUser={props.isuser} isUppeCase={props.isuppercase} isSymbolCase={props.isymbolcase} /> </Route>

投稿2020/04/09 03:44

編集2020/04/09 03:45
hoshi-takanori

総合スコア7895

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

satodesu

2020/04/09 03:51

上記のように書きましたが識別子が必要ですというエラーになってしまします
hoshi-takanori

2020/04/09 03:54

そのエラーはどこで出てますか? また、エラーメッセージはコピペしてください。
satodesu

2020/04/09 04:14 編集

<UserCreateで出ています。 エラーメッセージ 識別子が必要です。ts(1003)
hoshi-takanori

2020/04/09 04:01

PasswordComplexities のソースがないとどうしようもありません。ってか、今回の質問とは無関係では?
satodesu

2020/04/09 04:04

今回の質問とは無関係とは?? Route の component 属性にはコンポーネントの名前 (つまり UserCreate だけ) しか書けません。 <UserCreate CountText=... /> を書きたければ、次のように子要素にすると良いでしょう。と言われたので コードを直したところ識別子が必要です。ts(1003)というエラーメッセージが出たので
satodesu

2020/04/09 04:05

<Route exact path={`${BaseUrl}/${Paths.user}`} <UserCreate CountText={props.minimumLength} isUser={props.isuser} isUppeCase={props.isuppercase} isSymbolCase={props.isymbolcase} /> </Route>
hoshi-takanori

2020/04/09 04:07

今回のソースのどこに PasswordComplexities が出てくるんですか?
hoshi-takanori

2020/04/09 04:08

あ、path={`${BaseUrl}/${Paths.user}`} の後ろに > が抜けてますね。
satodesu

2020/04/09 04:15 編集

PasswordComplexitiesなんてどこに書いてあるでしょうか? ↑自分で書いて間違えていました。すいません。UseCreateです
satodesu

2020/04/09 04:13

>をつけると それ以降の構文にエラーが出てしまいます。 エラー内容 'Route' の対応する JSX 終了タグが必要です。t
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問