索引被注入自身而不是 templateUrl
Index is getting injected into itself instead of templateUrl
编辑:问题底部的解决方案。
因此,很难提供所有代码,因为这种行为只发生在一个非常大的项目的上下文中,但基本上我的路由显示的不是路由的 templateUrl,而是注入了索引进入索引,然后该索引也不显示 templateUrl。
我正在尝试用 vanilla ui-router 替换 Foundation for Apps 路由。我已经按照步骤 here 去除了 Foundation 的路由,但似乎我仍然遇到某种冲突。
这绝对让我抓狂。我的配置如下所示:
.config(['$stateProvider', $urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('/', {
url: '/',
templateUrl: "<div><h1>Test</h1></div>"
})
;
}])
无论我在 templateUrl 中放入什么,它都被替换为 index.html,我最终得到一个索引中的索引。
如有任何帮助,我们将不胜感激!
解决方案:
看起来,无论出于何种原因,如果模板路径无法解析,ui-router 会注入索引。 (它也可以简单地注入父模板,所以在这种情况下它是索引,但在其他情况下它可能略有不同,我不确定。查看 Javier Vargas 在他对他的评论中提供的 link回答更多信息。)所以如果我有:
.state('home', {
url: '/home',
templateUrl: 'INCORRECT PATH'
}
在我的情况下结果是状态注入index.html。
对于在 Foundation for Apps 项目的上下文中使用 ui-router 进行路由的特定问题,模板的路径是 /templates/myhtmlfiles.html,因此状态看起来像这样:
.state('home', {
url: '/home',
templateUrl: '/templates/home.html'
}
这是因为 Foundation for Apps 的路由插件将 "templates" 视为 root,但 ui-router 将您的工作目录视为 root(这可能是 "client"、"app",等等,但在 Foundation for Apps 安装的上下文中,它将是 /templates 之上的一个目录,因此您必须将其添加到路径中。)
感谢下面的答案帮助我弄清了为什么索引会突然进入 ui-视图 div(重申一下,这是模板的错误路径。如果您如果您遇到此问题,请检查路线。如果您需要测试,请将 templateUrl: 替换为 template: 'test' 并查看它是否被插入。)
除了 templateUrl 之外,您不应该使用 template 吗?
编辑:问题底部的解决方案。
因此,很难提供所有代码,因为这种行为只发生在一个非常大的项目的上下文中,但基本上我的路由显示的不是路由的 templateUrl,而是注入了索引进入索引,然后该索引也不显示 templateUrl。
我正在尝试用 vanilla ui-router 替换 Foundation for Apps 路由。我已经按照步骤 here 去除了 Foundation 的路由,但似乎我仍然遇到某种冲突。
这绝对让我抓狂。我的配置如下所示:
.config(['$stateProvider', $urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('/', {
url: '/',
templateUrl: "<div><h1>Test</h1></div>"
})
;
}])
无论我在 templateUrl 中放入什么,它都被替换为 index.html,我最终得到一个索引中的索引。
如有任何帮助,我们将不胜感激!
解决方案:
看起来,无论出于何种原因,如果模板路径无法解析,ui-router 会注入索引。 (它也可以简单地注入父模板,所以在这种情况下它是索引,但在其他情况下它可能略有不同,我不确定。查看 Javier Vargas 在他对他的评论中提供的 link回答更多信息。)所以如果我有:
.state('home', {
url: '/home',
templateUrl: 'INCORRECT PATH'
}
在我的情况下结果是状态注入index.html。
对于在 Foundation for Apps 项目的上下文中使用 ui-router 进行路由的特定问题,模板的路径是 /templates/myhtmlfiles.html,因此状态看起来像这样:
.state('home', {
url: '/home',
templateUrl: '/templates/home.html'
}
这是因为 Foundation for Apps 的路由插件将 "templates" 视为 root,但 ui-router 将您的工作目录视为 root(这可能是 "client"、"app",等等,但在 Foundation for Apps 安装的上下文中,它将是 /templates 之上的一个目录,因此您必须将其添加到路径中。)
感谢下面的答案帮助我弄清了为什么索引会突然进入 ui-视图 div(重申一下,这是模板的错误路径。如果您如果您遇到此问题,请检查路线。如果您需要测试,请将 templateUrl: 替换为 template: 'test' 并查看它是否被插入。)
除了 templateUrl 之外,您不应该使用 template 吗?