Questions tagged «routing»

有关将URL映射到控制器和操作的问题。

4
如何在Symfony布局中获取_locale变量?
我正在一个具有2种语言的网站上使用Symfony 2,并且我想根据用户区域设置语言更改路线模式! 例: user_login_en: pattern: /en/user/login.html defaults: { _controller: SfErrorsAppBundle:User:login, _locale: en } user_login_fr: pattern: /fr/utilisateur/connexion.html defaults: { _controller: SfErrorsAppBundle:User:login, _locale: fr} 在模板内部,这并不困难,我只需要将$ this-> get('session')-> getLocale()从控制器传递到模板... 要上班,我必须打电话给我的路线: $router->generate('user_login_'.$locale, array()); 但是在我的布局中,我当然有一个菜单和一个带有链接的侧边栏,所以我想让locale变量使用它!所以我的问题很简单:如何在“布局”模板中获取此变量?否则,您是否有任何想法根据语言更改模式? 原因是我想为所有用户提供漂亮的路线,无论他们是英语还是法语……而且出于搜索引擎优化的原因!

6
Next.js从/重定向到另一个页面
我是Next.js的新手,并且想知道如何从起始页(/)重定向到/ hello-nextjs。用户加载页面后,确定路径是否=== /重定向至/ hello-nextjs 在react-router中,我们执行以下操作: <Switch> <Route path="/hello-nextjs" exact component={HelloNextjs} /> <Redirect to="/hello-nextjs" /> // or <Route path="/" exact render={() => <Redirect to="/hello-nextjs" />} /> </Switch>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.