加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 无法直接从浏览器访问Angular Component

发布时间:2020-12-17 17:22:00 所属栏目:安全 来源:网络整理
导读:我有一个使用Angular 1.5组件的小型Web应用程序.当我启动服务器时,浏览器会将我重定向到 http://127.0.0.1:50001/welcome,这是预期的,并显示欢迎页面.如果我想创建一个新用户,我单击该链接,URL将更改为 http://127.0.0.1:50001/welcome/newUser,并且新用户表
我有一个使用Angular 1.5组件的小型Web应用程序.当我启动服务器时,浏览器会将我重定向到 http://127.0.0.1:50001/welcome,这是预期的,并显示欢迎页面.如果我想创建一个新用户,我单击该链接,URL将更改为 http://127.0.0.1:50001/welcome/newUser,并且新用户表单将会出现.

当我尝试直接访问URL(或刷新页面)时会出现问题 – 页面根本无法加载.控制台中没有出现错误 – 没有任何反应.

我的配置如下:

根组件:

.component('webGuiComponent',{
  template: '<ng-outlet></ng-outlet>',$routeConfig: [
    { path: '/welcome/...',name: 'Welcome',component: 'welcomeComponent',useAsDefault: true }
  ]
})

.value('$routerRootComponent','webGuiComponent');

欢迎组件:

.component('welcomeComponent',{
  template: '<header></header><ng-outlet></ng-outlet>',$routeConfig: [
    { path: '/',name: 'Index',component: 'indexComponent',useAsDefault: true },{ path: '/newUser',name: 'NewUser',component: 'newUser' }
  ]
})

.component('indexComponent',{
  templateUrl: '/app/components/welcome/index.html'
});

新用户组件:

.component('newUser',{
  controller: 'userController',templateUrl: '/app/components/user/new.html'
})

导航链接使用标准ng-links:

<a class="navbar-brand" ng-link="['/Welcome/Index']">Web GUI</a>
<a class="navbar-brand" ng-link="['/Welcome/NewUser']">Sign Up</a>

有没有人知道为什么导航通过ng-link完成,但直接访问URL时没有?

解决方法

您必须为可能在客户端定义的路径的所有路径添加服务器端路由,这将路由您的主页面.实施取决于您使用的服务器端技术.

或者你必须使用#based Url’s

说明

如果您没有基于#的URL浏览器转到服务器来获取资源但没有找到任何内容.因此,当您定义服务器端路由时,它将为主页面提供服务,然后进行客户端路由.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读