本文介绍了在angular-ui-router上输入路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 -router的此演示一个WordPress站点来托管javascript文件(应用作者并非打算使用此文件,但仍然展示了我的问题).角度应用程序具有/login路由,如果我单击主页上的链接,则会加载该角度应用程序的login模板.但是,如果我输入url http://localhost:8888/login,它将显示WordPress登录页面,即它不是由angular-ui-router处理的,这使得它作为路由器是无用的/不可预测的.

I'm playing around with this demo of the angular-ui-router using a WordPress site to host the javascript file (which isn't intended by the app author but demonstrates my problem nonetheless). The angular app has a /login route, which, if I click the link to on the homepage, loads the login template of the angular app. However, if I type in the url http://localhost:8888/login it shows the WordPress login page i.e. it's not handled by the angular-ui-router, which makes it kind of useless/unpredictable as a router.

问题:是否有一种方法可以使angular-ui-router处理浏览器中键入的路由,或者是否有角度路由器可以处理浏览器中键入的路由?

Question: Is there a way to get angular-ui-router to handle a route that's typed in the browser, or is there an angular router that will handle typed in routes in the browser?

背景:我将使用angular作为WordPress网站的前端,它能够处理在浏览器中放置的路由(例如对于http:localhost:8888/2015/10/10/my-wordpress-post

Background: I was going to use angular as a front-end for a WordPress site and it's pretty important that it be able to handle routes dropped in the browser, for example, for http:localhost:8888/2015/10/10/my-wordpress-post

这是处理login路线的代码

'use strict';
2

3 routes.$inject = ['$stateProvider'];
4

5 export default function routes($stateProvider) {
6   $stateProvider
7     .state('login', {
8       url: '/login',
9       template: require('./login.html'),
10       controller: 'LoginController',
11       controllerAs: 'login'
12     });
13 }

推荐答案

问题是您的服务器正在侦听基于url的请求.如果您在Angular页面上并单击链接,则说明您使用的是HTML5推送状态.如果您输入的不是URL,则服务器将在角度输入之前处理该URL.最简单的解决方案是将Wordpress应用安装在子目录中,并使用根目录来提供Angular应用.

The problem is that your server is listening for url-based requests. If you're on an Angular page and click a link, you're using HTML5 push-state. If you type in a URL, you're not, your server handles it before the angular ever does. The easiest solution would be to install the Wordpress app in a subdirectory, and use the root to serve an Angular app.

这篇关于在angular-ui-router上输入路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 01:47