有没有办法让Routify忽略特定的URL路径?

huangapple go评论79阅读模式
英文:

Is there a way to have Routify ignore certain URL paths?

问题

我们正在使用Go(Buffalo)来为单页应用程序(SPA)提供API和静态资源服务,该应用程序使用Svelte和Routify。

然而,我希望某些路由(例如"/auth/login")被Routify忽略,而是由Go/Buffalo服务器处理这些请求。

Routify是否有相应的设置可以实现这一点?

我看到了ignore build config,但似乎是用于在构建路由列表时告诉Routify忽略某些文件,而不是忽略特定的URL路径。

(如果必要的话,我可以将我们的/auth/login调用作为XHR调用来处理,然后根据响应手动重定向浏览器,但直接让浏览器访问/auth/login会更好/更简单。)


更新: 显然,直接访问/auth/login(例如在新标签页中)可以实现我想要的效果。只有在SPA中点击链接时才会被Routify拦截。因此,我的问题仍然存在,只是略有改变:

有没有办法告诉Routify不要拦截指向某些URL路径的链接,而是让浏览器直接访问该URL(离开SPA)?

英文:

We're using Go (Buffalo) to serve up both an API and the static assets for a Single-Page Application (SPA) that uses Svelte and Routify.

However, I'd like to have certain routes (e.g. "/auth/login") be ignored by Routify and instead go to the Go / Buffalo server, for handling those requests.

Is there a Routify setting for that?

I see the ignore build config, but that seems to be for telling Routify to ignore certain files when building the list of routes, not ignoring certain URL paths.

(If I have to, I might be able to get our /auth/login call to work as an XHR call, then actually manually redirect the browser based on the response, but it would be nicer/simpler to simply allow the browser to go to /auth/login directly.)


UPDATE: Apparently going to /auth/login directly (e.g. in a new tab) does what I want. It's just clicking a link in the SPA that gets intercepted by Routify. So my question still stands, though slightly altered:

Is there a way to tell Routify not to intercept links to certain URL paths, but to simply let the browser go to that URL (leaving the SPA)?

答案1

得分: 3

target属性在链接标签上实现了我想要的效果。太好了,找到了适当的文档!

如果你想使用锚点的默认导航行为,可以通过添加target属性来实现。

Routify将忽略所有带有target属性的锚点。

来源:
https://www.routify.dev/guide/navigation

所以在我的情况下,我需要这样做:

<a href="/auth/login" target="_self">登录</a>
英文:

The target attribute on a link tag does what I was after. Hooray for finding the appropriate documentation!

> If you want to use anchor's default navigation behaviour you can do so by adding the target attribute.
>
> Routify will ignore all anchors with target attribute.

Source:
https://www.routify.dev/guide/navigation

So in my case, I needed to do this:

&lt;a href=&quot;/auth/login&quot; target=&quot;_self&quot;&gt;Login&lt;/a&gt;

huangapple
  • 本文由 发表于 2022年6月22日 23:01:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/72717856.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定