angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng build --prod breaks routes error "cannot match any routes"

Open estradamarkie opened this issue 9 years ago • 23 comments

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.0 node: 6.9.2 os: win32 x64 @angular/common: 4.2.2 @angular/compiler: 4.2.2 @angular/core: 4.2.2 @angular/forms: 4.2.2 @angular/http: 4.2.2 @angular/platform-browser: 4.2.2 @angular/platform-browser-dynamic: 4.2.2 @angular/router: 4.2.2 @angular/cli: 1.0.0 @angular/compiler-cli: 4.2.2

Repro steps.

Simple steps to reproduce this bug. Before bundling the app it works all fine, but once its bundled up it somehow can't find any routes on IE but works on chrome just fine.

ng build --prod --base-href ./ this seems to work on chrome, but not IE if the base is just / it doesn't work at all. Then just redirects me to the IIS root folder. Tried --base-href='/Demo/AppFiles/ didn't work as well.

I copied the dist folder and stick it to my IIS server.

Router.ts

const routes: Routes = [
    {
        path: '',
        component: CatalogsComponent,
        pathMatch: 'full'
    }
];

export const appRoutingProviders: any[] = [];

// - Updated Export
export const routing = RouterModule.forRoot(routes);

The log given by the failure.

ERRORError: Uncaught (in promise): Error: Cannot match any routes. URL 
Segment: 'SalesNew
Error: Cannot match any routes. URL Segment: 'SalesNew'
   at Anonymous function 

Also when I refresh the page it goes to 404 error.

Directory tree

/root
  /Appfolder(SalesNew
    /AppFiles (index.html, etc)

estradamarkie avatar Jun 20 '17 21:06 estradamarkie

@mgechev sir i have the same problem in prod , but only the first time you open the app and after refresh the page every thing works fine kindly advice

ElTamero avatar Dec 27 '18 07:12 ElTamero

This solved it for me: https://angular.io/api/common/APP_BASE_HREF

JayEnaR avatar Aug 08 '19 11:08 JayEnaR

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.