Livereload Html5的pushState的与AngularJS,ui.Router和自耕农

编程入门 行业动态 更新时间:2024-10-19 20:30:02
本文介绍了Livereload Html5的pushState的与AngularJS,ui.Router和自耕农的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要修正我的角度JS应用程序的livereload。我使用yoeman UI路由器与HTML5推的状态。

I want to fix the livereload with my angular js app. I am using yoeman ui-router with html5 push state.

什么是一个必须做的?

推荐答案

指数对于searchengines必须添加以下到< HEAD> 您的index.html的

The index For the searchengines you have to add the following to the <head> of your index.html

<meta name="fragment" content="!"> <base href="/">

的应用在你app.js,你必须注入下面的依赖关系,并添加功能。

The app In your app.js you have to inject the following dependencies and add the functions.

angular .module('yourApp', [ 'ngAnimate', 'ngCookies', 'ngResource', 'ngSanitize', 'ui.router', ]) .config(function ($stateProvider, $urlRouterProvider, $locationProvider) { // HTML5 PUSH STATE $locationProvider.html5Mode(true).hashPrefix('!'); $urlRouterProvider.otherwise('/'); // STATES $stateProvider .state('home', { url: '/', templateUrl: 'views/home.html', controller: 'homeCtrl' }); });

的middelware

这个问题的解决办法是适应的Connect-modrewrite中间件。

The solution to this problem is to adapt the connect-modrewrite middleware.

安装与您的控制台内的节点packetmanager中间件在yeomanfolder

Install the middleware with the node packetmanager within your console in your yeomanfolder

npm install connect-modrewrite

然后调整Gruntfile.js

Then adapt the Gruntfile.js

var modRewrite = require('connect-modrewrite'); livereload: { options: { open: true, base: [ '.tmp', '<%= yeoman.app %>' ], middleware: function (connect, options) { var middlewares = []; middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]'])); //Matches everything that does not contain a '.' (period) options.base.forEach(function (base) { middlewares.push(connect.static(base)); }); middlewares.push( connect.static('.tmp'), connect().use( '/bower_components', connect.static('./bower_components') ) ); return middlewares; } } },

现在用命令开始你的呼噜声

Now start your grunt with the command

grunt serve

更多推荐

Livereload Html5的pushState的与AngularJS,ui.Router和自耕农

本文发布于:2023-11-01 18:11:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550044.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自耕农   pushState   Livereload   Router   ui

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!