Relative path to assets folder is off in github pages angular build

Discussão em 'Angular' iniciado por JRT, Fevereiro 22, 2025.

  1. JRT

    JRT Guest

    https://jamestroxel.github.io/smo-study/

    i have pushed my angular web app to a gh-pages branch of my repo and set up github pages to publish from the docs folder generated in the root folder there after running ng build --output-path docs --base-href /smo-study/

    I have been following these steps but am running in to a strange problem ive never seen before: https://v17.angular.io/guide/deployment#deploy-to-github-pages

    The paths to the image files and data files in the assets folder no longer point to the right location once its deployed. for example, when i inspect the html in the browser, the path to an image will be set to "../../assets/images/filename.jpg" which results in a 404 error for that file. however, if I edit the path in the browser html to "./assets/images/filename.jpg", the image file renders.

    [​IMG]

    In my src folder my folder structure is set up like this:

    [​IMG]

    I've tried moving the assets folder into the app folder prior to running the build but that produces the same result.

    I've also modified the outputPath in the angular.json from "dist/app" to "docs" and currently the build section there is setup like this:

    "sourceRoot": "src",
    "prefix": "app",
    "architect": {
    "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
    "outputPath": "docs",
    "index": "src/index.html",
    "main": "src/main.ts",
    "polyfills": "src/polyfills.ts",
    "tsConfig": "tsconfig.app.json",
    "inlineStyleLanguage": "scss",
    "assets": [
    "src/favicon.ico",
    "src/assets"
    ]


    I've only seen this problem deploying angular to github pages so wondering if there something else special with my directory or something that i need to do for this kind of deployment

    Continue reading...

Compartilhe esta Página