Angular 4 application on Github Pages

强颜欢笑 提交于 2019-12-06 10:49:46

You can use the following package https://www.npmjs.com/package/angular-cli-ghpages

When using this commad ng build --prod --base-href "https://USERNAME.github.io/REPOSITORY_NAME/"

I switched out to my repository which is called ePortfolio, I typed it in as eportfolio, It seems that the letter P had to be capital for it to work.

The easiest way that I found is a 2 steps process. First of, you need to know that Github Pages doesn't handle well base href and so disabling the pushState and removing the base href was enough on my side to get going.

Here's the steps:

1- remove the backslash "/" from the base href in your index.html

<base href="">

2- Disable the pushState by adding the argument {useHash: true}. In my case, I have an app-routing.module.ts which I updated with following code:

@NgModule({
   imports: [RouterModule.forRoot(routes, {useHash: true})], // <-- HERE
   exports: [RouterModule],
})

Then publish to a Github Page and we're in business

EDIT

Just doing step 2 is enough for it to work {useHash: true}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!