たとえば、正規表現を使用してパラメータを制約する方法は本当にわかりません。
これら2つのルートを区別するにはどうすればよいですか?
<Router>
<Route path="/:alpha_index" component={Child1} />
<Route path="/:numeric_index" component={Child2} />
</Router>
「/ 123」が最初のルートを起動しないようにしますか?
反応-ルータV4は、今あなたがのparamsに一致するように正規表現を使用することができます- https://reacttraining.com/react-router/web/api/Route/path-string
const NumberRoute = () => <div>Number Route</div>;
const StringRoute = () => <div>String Route</div>;
<Router>
<Switch>
<Route exact path="/foo/:id(\\d+)" component={NumberRoute}/>
<Route exact path="/foo/:path(\\w+)" component={StringRoute}/>
</Switch>
</Router>
詳細:https : //github.com/pillarjs/path-to-regexp/tree/v1.7.0#custom-match-parameters
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加