且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

reactjs - 404页面 - 语言参数缺少处理问题

更新时间:2023-02-19 19:30:34

我想你说的问题是你希望用户能够在URL中不提供语言参数?现在,如果他们不提供它们,他们会被抛入Error组件?您可以使用:langURL?

I think you're saying the problem is that you want the user to be able to not provide the language parameter in the URL? And that right now if they don't provide it they're thrown into the Error component? You can make that parameter optional by using :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>