我有angularJS
路由:
angular.module('diam8App', ['ngRoute'])
.config(['$routeProvider','$locationProvider',
function($routeProvider,$locationProvider) {
$routeProvider.
when('/', {
templateUrl: 'main.html'
}).
when('/calculator/', {
templateUrl: 'calculator.html',
controller: 'calculatorCtrl'
}).
when('/contact/', {
templateUrl: 'contact.html',
controller: 'contactCtrl'
}).
otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
}])
一切正常,但是当我尝试通过网址直接获取子网页时,例如mydomain.com/contact
,那么我正在接收HTTP 502
。我认为从外部访问时路由不起作用。
所以我的问题是:有什么方法可以将用户重定向到主页,当他来自不同的页面时(来自main的路由必须正常工作)?可能需要.htaccess
或其他角度配置?
答案 0 :(得分:0)
服务器不考虑散列的所有内容,angularJS将处理这个问题。
如果您使用HTML5模式,则会删除“#”前缀。
由于搜索引擎优化而删除了'#',但这可以通过'!'来处理字首:
int connSock;
/*NodeA context maintenance */
struct NodeAStruct {
char ipAddr[20];
unsigned int portNum;
};
static int NodeAInstCount;
struct NodeAStruct NodeAInst[7];
int main()
{
pthread_t clientNodeA, serverNodeA;
pthread_create(&serverNodeA, NULL, serverNodeB_thread, "serverNodeA");
usleep(10000000);
pthread_join(clientNodeA, NULL);
pthread_join(serverNodeA, NULL);
return 0;
}
void* serverNodeB_thread(void* pString)
{
int listenSock, ret, flags, i;
struct sockaddr_in src_addr;
struct sockaddr_in servaddr;
struct sctp_initmsg initmsg;
struct sctp_event_subscribe events;
struct sctp_sndrcvinfo sndrcvinfo;
char sendBuffer[MAX_BUFFER+1];
unsigned int NodeA_PORT_NUM;
char* NodeA_IP_ADDR;
char from_ip[1024] = "", myip[2014] = "";
int addr_len = 0;
listenSock = socket( AF_INET, SOCK_STREAM, IPPROTO_SCTP );
bzero( (void *)&servaddr, sizeof(servaddr) );
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl( INADDR_ANY );
//servaddr.sin_addr.s_addr = htonl("127.0.0.1");
servaddr.sin_port = htons(MY_PORT_NUM_NodeB);
ret = bind( listenSock, (struct sockaddr *)&servaddr, sizeof(servaddr) );
/* Specify that a maximum of 5 streams will be available per socket */
memset( &initmsg, 0, sizeof(initmsg) );
initmsg.sinit_num_ostreams = 5;
initmsg.sinit_max_instreams = 5;
initmsg.sinit_max_attempts = 4;
ret = setsockopt( listenSock, IPPROTO_SCTP, SCTP_INITMSG,
&initmsg, sizeof(initmsg) );
listen( listenSock, 5 );
while( 1 ) {
char buffer[MAX_BUFFER + 1];
int len ;
bzero(buffer, MAX_BUFFER + 1);
printf("Awaiting a new connection\n");
connSock = accept( listenSock, (struct sockaddr *)NULL, (int *)NULL );
if(connSock == -1)
die("accept()");
else
{
printf("New client connected....\n");
addr_len = sizeof (src_addr);
recvfrom(connSock, buffer, sizeof(buffer), 0, &src_addr, &addr_len);
printf("Received message: %s from NodeA IP: %s Port: %u \n", (char*)buffer, inet_ntop(AF_INET, &src_addr.sin_addr, from_ip, sizeof(from_ip)), ntohs(src_addr.sin_port));
strcpy(NodeAInst[NodeAInstCount].ipAddr, inet_ntop(AF_INET, &src_addr.sin_addr, from_ip, sizeof(from_ip)));
NodeAInst[NodeAInstCount].portNum = ntohs(src_addr.sin_port);
printf("NodeA instance [%d] added \n", NodeAInstCount);
/* Send data to NodeA*/
strncpy(sendBuffer, "From NodeB", 12);
sendBuffer[12]='\0';
NodeA_PORT_NUM = NodeAInst[NodeAInstCount].portNum;
usleep(10000000);
ret = sctp_sendmsg( connSock, (void *)sendBuffer, (size_t)strlen(sendBuffer),
NULL, 0, 0, 0, 0, 0, 0 );
if(ret>0) {
printf("Data sent to NodeA \n");
}
else {
printf("Sending data to NodeA failed");
}
usleep(6000000);
NodeAInstCount++;
}
}
}
使用html5mode时,还需要在后端处理路由!
答案 1 :(得分:0)
带走' /' when('/calculator/',
的{{1}}并将此'/calculator'
用于$ routeProvider路径路径。