Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 无法直接从浏览器访问Angular Component大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个使用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浏览器转到服务器来获取资源但没有找到任何内容.因此,当您定义服务器端路由时,它将为主页面提供服务,然后进行客户端路由.

大佬总结

以上是大佬教程为你收集整理的angularjs – 无法直接从浏览器访问Angular Component全部内容,希望文章能够帮你解决angularjs – 无法直接从浏览器访问Angular Component所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。