I am using Angular to build a single-page application with routing in SharePoint. The only way I have been able to successfully use routing is to use Angular's HashLocationStrategy URL style but I would like to eliminate using this if possible.
The project's HTML file is injected into a page, myPage.aspx, using a Content Editor web part.
This is what my RoutingModule looks like:
const routes: Routes = [
{
path: 'transactions',
component: TransactionComponent,
},
{
path: '',
component: AppComponent,
},
];
@NgModule({
imports: [
// useHash eliminates "Cannot retrieve the URL specified in the Content Link property" error in SharePoint
RouterModule.forRoot(routes, { useHash: true })
],
exports: [RouterModule]
})
If I do not use HashLocationStrategy and navigate to https://mySite/SitePages/myPage.aspx/transactions, I am shown the following error message:
Cannot retrieve the URL specified in the Content Link property. For more assistance, contact your site administrator.
I am using the following build command:
ng build --prod --deploy-url=https://mySite/_catalogs/masterpage/Custom/myPage/dist/ --base-href=https://mySite/SitePages/myPage.aspx. I have found it necessary to use the --deploy-url flag so the page can locate the project's other files and the --base-href flag so features in SharePoint like page editing work.
How can I get routing to work without using HashLocationStrategy?