- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我开始学习如何在网络应用程序中使用backbonejs,但应用程序启动时,我遇到了默认路由的一些问题。
这是我的脚本
var AppRouter = Backbone.Router.extend({
routes: {
"user/:id": "getUser",
"*actions": "defaultRoute"
}
});
var app_router = new AppRouter;
app_router.on('route:defaultRoute', function() {
$("#content").load("pages/page1.html");
});
app_router.on('route:getUser', function(id) {
$("#content").load("pages/user.php?id="+id);
});
Backbone.history.start();
当您使用类似 http://www.myapp.com 的应用程序时默认路由未加载。
当我单击路由中未引用的链接时,将加载 page1.html。
我的问题是:当我进入应用程序时如何设置默认路由?
谢谢
最佳答案
您的代码演示了backboneJS的一种不寻常的用法,因为您将完整的HTML或页面加载到div容器中,而不是使用主干 View 和下划线模板。
无论如何,您可能需要考虑以下实现,而不是使用 app_router.on(...) 语法。
考虑以下实现:
var AppRouter = Backbone.Router.extend({
routes: {
"":"defaultRoute" //The router will default to this route if no other routes are matched ("")
"user/:id": "getUser",
...more routes
},
defaultRoute:function(){
...default route functionality
},
getUser:function(id){
...
}
});
关于javascript - Backbonejs 和 defaultRoute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31054046/
我正在玩我的网络应用程序,react-router包,我想做一些嵌套路线。这是我所做的 由于 DefaultRoute,
我正在设置一个新的测试,并且我想进行相反的操作。 router = DefaultRouter() router.register('profile', views.UserProfileViewSe
我开始学习如何在网络应用程序中使用backbonejs,但应用程序启动时,我遇到了默认路由的一些问题。 这是我的脚本 var AppRouter = Backbone.Router.extend({
我正在阅读http://www.django-rest-framework.org/api-guide/routers#usage并且无法理解 base_name 是什么。我还尝试添加自定义操作,但路
我想在rest_framework 中为几个类别创建不同的 View 。但所有类别都来自同一模型。 令我印象深刻的是,这些类别可以作为关键字传递给 urlpatterns (或通过 DefaultRo
您将如何保护 DefaultRouter() 以便用户在登录前无法查看 API Root? class OrderViewSet(viewsets.ReadOnlyModelViewSet):
当我将 ASP.NET WebAPI 解决方案发布到远程 IIS 服务器 时,我收到错误消息: Message: System.ArgumentException: A route named 'De
我将react-router与ES6类一起使用,它不断抛出错误 Uncaught TypeError: Cannot call a class as a function 指的是默认路由的声明。大部分
我想知道下面示例中的 IndexRoute 和 DefaultRoute 有什么区别?据我了解,在这两种情况下 Home 都会被渲染,对吗? 和 最佳答案 Defaul
我想定义一个访问某个api的路径。到目前为止什么有效(urls.py): router = routers.DefaultRouter() router.register(r'test', views
我正在使用 DRF 提供的 DefaultRouter,因为我需要一个根 api View 。但是,该 View 上的项目没有任何逻辑顺序。我查看了源代码,发现每个条目都被放入字典中(本质上没有排序)
我正在创建一个简单的 Python API,其中包含两个名为 snippets 的应用程序。和 polls .对于我的 API 的单一入口点,我正在使用 DefaultRouter类而不是常规的基于函
我有以下内容: 当使用 DefaultRoute 时,SearchDashboard 呈现不正确,因为任何 *Das
我正在努力生成文档(或者简单地 - 整个项目)。我对 Django 和 Python 几乎不陌生,所以也许我的问题很微不足道。 我在 Django Rest Framework 项目中有一堆定义良好的
我有一个 Django 项目,其中我制作了 3 个不同的应用程序:“blog”、“users”、“api”。这是一个可以使用模型帖子发布消息的网站。我想使用 Django Rest API 来访问模型
我是一名优秀的程序员,十分优秀!