4

I'm using AngularJS to handle my urls with html5mode turned on. I'm also using the gulp-angular generator to build the project.

Situation:

index.js

   $locationProvider
        .html5Mode(true);

index.html

<!-- build:css({.tmp,src}) styles/app.css -->
<!-- inject:css -->
<link rel="stylesheet" href="app/index.css">
<!-- endinject -->
<!-- endbuild -->
<base href="/" />

Problem

When url is example.com/somepage, index.css is gotten from example.com/app/index.css but when url is example.com/somepage/somedeeperpage, and I refresh the page, index.css is gotten from example.com/somepage/app/index.css

I want to be able to use the relative paths as by default in the angular-gulp generator.

Do I have to change to base tag, or index.css rel path in the gulpfile?

Strangely, the relative path is working fine for finding index.js

Kind regards

1 Answer 1

5

Edit: just figured out that if I put the tag before the injection of styles it works... My index.html looks like this now:

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <base href="/">
    <!-- build:css({.tmp/serve,src}) styles/app.css -->
    <!-- inject:css -->
    <!-- endinject -->
    <!-- endbuild -->
</head>

Previous answer :

Had the same issue, made this work by adding in my index.html file and by changing the gulp-inject config in gulp/inject.js :

Before :

var injectOptions = {
  ignorePath: [options.src, options.tmp + '/serve'],
  addRootSlash: false
};

After :

var injectOptions = {
  ignorePath: [options.src, options.tmp + '/serve']
};
Sign up to request clarification or add additional context in comments.

2 Comments

just got this issue and first post solve my issue. Thanks man.
I never would have tried moving the base tag up in the head! Thanks for posting the solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.