Link在AngularJS没有叫瓶端点 [英] Link in AngularJS not calling Flask endpoint
问题描述
code片段:
的app.config
app.config
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
$urlRouterProvider
.when('logout', '/logout')
.otherwise('/');
有关HTML
Relevant HTML
<li><a href="/logout">Logout</a></li>
瓶端点
Flask endpoint
@app.route("/logout")
@login_required
def logout():
logout_user()
return redirect(url_for("login"))
我还设置&LT;基本href =/&GT;&LT; /基&GT;
在我的HTML的标题。点击链接,但是,不造成任何进入发生(从字面上没有任何反应)。
I have also set <base href="/"></base>
in my HTML's header. Clicking on the link, however, does not result into anything happening (literally nothing happens).
怎么办?
推荐答案
凭借阅读AngularJS文档两次解决了这一发现的这个小宝石的存在。这里提供了答案,这样它可以帮助其他人谁也开始在烧瓶角度发展。
Solved this by virtue of reading the AngularJS documentation twice and found this little gem there. Providing the answer here so that it helps others who are beginning developing in Flask-Angular.
要报价:
当您使用HTML5历史API模式,你不需要特殊的
hashbang链接。所有你需要做的是定期指定的URL链接,这样
如:&LT; A HREF =/?一些富=酒吧&GT;链接&LT; / A&GT;
Html link rewriting
When you use HTML5 history API mode, you will not need special hashbang links. All you have to do is specify regular URL links, such as:
<a href="/some?foo=bar">link</a>
当用户点击这个链接,
- 在旧版浏览器,网址修改
/index.html#!/一些?富=栏
- 在新版浏览器,网址修改
/一些?富=栏
- In a legacy browser, the URL changes to
/index.html#!/some?foo=bar
- In a modern browser, the URL changes to
/some?foo=bar
在类似以下的情况下,链接不会重写;相反,
浏览器将执行一个完整的页面重载以原文链接。
In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link.
- 包含
目标
元素结果链接
例如:&LT; A HREF =/转/链路A = B?TARGET =_自我&GT;链接&LT; / A&GT;
- 绝对链接,去到不同的域
例如:&LT; A HREF =http://angularjs.org/&GT;链接&LT; / A&GT;
- 以'/'链接,导致不同的基本路径
例如:&LT; A HREF =/不是我的基地/链接&GT;链接&LT; / A&GT;
- Links that contain
target
element
Example:<a href="/ext/link?a=b" target="_self">link</a>
- Absolute links that go to a different domain
Example:
<a href="http://angularjs.org/">link</a>
- Links starting with '/' that lead to a different base path
Example:
<a href="/not-my-base/link">link</a>
基本上,改变这个:
<li><a href="/logout">Logout</a></li>
这样:
<li><a href="/logout" target="_self">Logout</a></li>
解决这个问题。
这篇关于Link在AngularJS没有叫瓶端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!