Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angularjs使用直接url访问视图_Javascript_Angularjs_Angular Ui Router - Fatal编程技术网

Javascript Angularjs使用直接url访问视图

Javascript Angularjs使用直接url访问视图,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,如果我使用或。。。一切正常,我可以访问所有视图。 当我像http://localhost/#/someurl它不起作用 如果我单击导航栏中的一个按钮,然后通过或传递我的url,它就会工作 根玉 ng-include(src="'partials/navbar.html'") div(ui-view="") navbar.jade nav.navbar.navbar-default .容器液体 .导航栏标题 a、 navbar品牌(href=“#”)开放式服务概要 ul.nav.

如果我使用
。。。一切正常,我可以访问所有视图。 当我像
http://localhost/#/someurl
它不起作用

如果我单击导航栏中的一个按钮,然后通过
传递我的url,它就会工作


根玉

ng-include(src="'partials/navbar.html'")
div(ui-view="")
navbar.jade nav.navbar.navbar-default .容器液体 .导航栏标题 a、 navbar品牌(href=“#”)开放式服务概要

        ul.nav.navbar-nav
            li
                a(ui-sref="home") Home
            li
                a(ui-sref="test1") test1
            li
                a(ui-sref="test2") test2
所以如果我想去

http://localhost/#/otherview
它不起作用,我得到一个带有导航栏的空白页面,但是如果我点击test1,url的形式是

http://localhost/#/otherview
它是有效的。这似乎有点逻辑,因为root.jade上的
div(ui view=“”)
将只加载将在导航栏上单击的VEW,可能吧?有人有主意吗

root.html

'use strict';
angular.module('myApp', ['ngAnimate', 'ngCookies', 'ngResource', 'ui.router', 'ngSanitize', 'ngTouch']).config(function($stateProvider) {
   $stateProvider.state('home', {
    url: '/',
    templateUrl: 'home.html'
  }).state('services', {
    url: '/services/:type',
    templateUrl: 'services.html'
  }).state('services.detail', {
    url: '/:id',
    templateUrl: 'detail.html'
  }).state('test1', {
    url: '/test1',
    templateUrl: 'test1.html'
  }).state('test2', {
    url: '/test2',
    templateUrl: 'test2.html'
  });
});

根玉

ng-include(src="'partials/navbar.html'")
div(ui-view="")
ng include(src=“'partials/navbar.html”)
div(ui view=“”)

navbar.jade-添加div(ng视图)

您可以将您的分区另存为
.jade
扩展名。在路由逻辑中,删除
.html
扩展,例如

.state('test1', {
    url: '/test1',
    templateUrl: 'test1.html'
  }).state('test2', {
    url: '/test2',
    templateUrl: 'test2.html'
  })
变成

.state('test1', {
    url: '/test1',
    templateUrl: 'test1'
  }).state('test2', {
    url: '/test2',
    templateUrl: 'test2'
  })

试试看。建议您仔细阅读jade,并显示定义ui路由器状态的代码,请使用代码@user3235881我想你需要删除return。只需$stateProvider.state。请按照@Alberto的建议尝试!我做了,它仍然工作,但仍然无法访问直接url的视图:(它不再工作,它不再加载视图