AngularJS ngRoute直接参与访问 [英] AngularJS ngRoute direct part access

查看:238
本文介绍了AngularJS ngRoute直接参与访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正常工作与ngRoute,但是当我试图直接访问我的部分(从地址栏),它返回只是部分(不包括主页)。如何从直接访问隐藏这些部分?

My app works fine with ngRoute, but when I'm trying to access my parts directly(from address bar), it returns just the part (without main page). How to hide these parts from a direct access?

说明:
我有2个街区的网站。第一个是一个菜单和第二个是一个内容(我的行程的部分之一)。菜单有链接:#/主和#/账户。当我$按钮p $ PSS,它工作正常(左菜单和内容)。但是,如果我更改URL从本地主机:8080 /#/帐户为localhost:8080 /帐户,它呈现净含量,没有菜单。我想隐藏访问本地主机:8080 /帐户或使其渲染菜单内容

Explanation: I have a site with 2 blocks. First is a menu and second is a content (one of my route's part). Menu has links: "#/main" and "#/account". When I press on the buttons, it works fine (left menu and content). But if I change URL from localhost:8080/#/account to localhost:8080/account, it renders ONLY content, without menu. I want to hide access to localhost:8080/account or make it to render a content with a menu.

推荐答案

您的问题是最有可能不是你的AngularJS路由,但服务器的路由。当你要求如本地主机页面:8080 /帐户,你的服务器说好了,我们只是提供了 /帐户文件。但是,这并不完全正确,因为你真正想要整个应用程序加载。这是一个常见的​​问题,并没有太糟糕来解决。

Your problem is most likely not with your AngularJS routing, but the routing from the server. When you request a page like localhost:8080/account, your server says "ok, let's JUST deliver the /account file". But that's not quite right, because you actually want the whole app to load. It's a common problem, and not too bad to solve.

我不知道你的后端看起来像什么,但这里与前preSS /节点的通用示例:

I don't know what your backend looks like, but here's a generic example with express/node:

var express = require('express'),
  routes = require('./routes');

app.get('/', routes.index);
app.get('*', routes.index);

到后端每个请求都应该开始渲染整个布局以加载我们的角度应用程序。只有这样,客户端呈现接管。

"Every request to the backend should initially render the complete layout in order to load our Angular app. Only then will the client-side rendering take over."

SRC:<一href=\"http://fdietz.github.io/recipes-with-angular-js/backend-integration-with-node-ex$p$pss/implementing-client-side-routing.html\" rel=\"nofollow\">http://fdietz.github.io/recipes-with-angular-js/backend-integration-with-node-ex$p$pss/implementing-client-side-routing.html

这篇关于AngularJS ngRoute直接参与访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆