Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

How to use html5Mode with Ionic?

$
0
0

You will have to create your own web server because 'ionic server' creates a server that don't support modRewrite.

Here what I did:

1- Web Server for Production ( Nodejs + Express)

server.js

2- Web Server for Development ( Nodejs + Gulp + BroswerSync + Connect History Api Fallback)

gulpfile.js

3- Gulp task for Mobile App build (with gulp-replace package)

When you put <base href="/"> inside the head tag in your index.html file, the application will work fine with Html5Mode enabled in a web browser, but in your mobile application you gotta use <base href="."> instead.

To automate this, I created a gulp task with gulp-replace node package to do the job for me:

gulp.task('build:device', ['sass', 'compressJs', 'jade-templates'],function () {
  return gulp.src(paths.jade[1])
  	.pipe(replace('base(href="/")', 'base(href=".")'))
    .pipe(jade())
    .pipe(gulp.dest('./www/'));
});

So before I run "ionic build android" i run "gulp build:device" .

4- Url paths Cautions

You will have to be careful with url paths.

  • href urls must start with "/". Ex.: <a href="/app/list">link</a>
  • src urls must start without "/". Ex.: <img src="img/banner.jpg">

Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>