2017-05-19 10 views
0

私はreactjsの新機能です - 言語切り替えのあるサイトで作業しています404ページとして使用するエラーコンポーネントを作成しようとしていますが、パラメータが定義されていない場合はデフォルトの言語を使用するようにサイトを自動的に設定/設定したり、エラーパスを設定してlangパラメータをリッスンします。reactjs - 404ページ - 言語paramには処理の問題があります

router.js現在この

<Switch> 
        <Route exact path='/' render={() => (<Redirect to='/de/dienstleistungen/geistiges-eigentum' />)} /> 
        <Route path='/:langURL/services' component={Services} /> 
        <Route path='/:langURL/dienstleistungen' component={Services} /> 
        <Route path='/services' component={Services} /> 
        <Route path='/:langURL/how-it-works' component={HowItWorks} /> 
        <Route path='/:langURL/anleitung' component={HowItWorks} /> 
        <Route path='/:langURL/features' component={Features} /> 
        <Route path='/:langURL/funktionen' component={Features} /> 
        <Route path='/:langURL/beliebte-projekte' component={BundleDetails} /> 
        <Route path='/:langURL/popular-projects' component={BundleDetails} /> 
        <Route component={Error} /> 
</Switch> 

答えて

0

のように見える私はあなたの問題は、ユーザーがURLに言語パラメータを提供しないことができるようにしたいということです言っていると思いますか?そして、今、彼らはそれを提供しない場合、彼らはエラーコンポーネントに投げ込まれている?あなたは:langURL?を使用して、そのパラメータをオプションにすることができます

<Switch> 
    <Route exact path='/' render={() => (<Redirect to='/de/dienstleistungen/geistiges-eigentum' />)} /> 
    <Route path='/:langURL?/services' component={Services} /> 
    <Route path='/:langURL?/dienstleistungen' component={Services} /> 
    <Route path='/services' component={Services} /> 
    <Route path='/:langURL?/how-it-works' component={HowItWorks} /> 
    <Route path='/:langURL?/anleitung' component={HowItWorks} /> 
    <Route path='/:langURL?/features' component={Features} /> 
    <Route path='/:langURL?/funktionen' component={Features} /> 
    <Route path='/:langURL?/beliebte-projekte' component={BundleDetails} /> 
    <Route path='/:langURL?/popular-projects' component={BundleDetails} /> 
    <Route component={Error} /> 
</Switch> 
+0

私はパスに誤差成分にルートパスを設定している場合=「/:?langURL」 - それでもエラーコンポーネントを有効にしますか? –

+0

ルートに既にリダイレクトがあります/ - - –

関連する問題