5

I set up a local IIS and a application with a directory called test:

enter image description here

Then in my browser I browse to: "http://localhost/test"

I have a route for this:

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

 @NgModule({
    imports: [
       RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
    ],
    exports: [RouterModule]
 })

 export class AppRoutingModule {}

But when I arrive at the login page, the browser removes the "test" and just does the "http://localhost/" in the browsers address, which is wrong.

The browser also don't get the assets now as "test" is missing: enter image description here Just for information, when I build the app, I build it with --baseHref=/test/

6
  • why you are browsing to localhost/test, you should browsing localhost only and your localhost should serve index.html. for assets base href will be used. Commented Jun 16, 2020 at 18:49
  • 1
    What you have should work. Maybe add enableTracing: true in your forRoot config and see if you can identify the problem Commented Jun 18, 2020 at 7:22
  • Please share your login component as well, maybe your login redirection needs to be change. Commented Jun 19, 2020 at 11:47
  • What version of angular? Commented Jun 20, 2020 at 10:33
  • Have you tried updating your deployUrl? Commented Jun 21, 2020 at 20:40

2 Answers 2

1

you set it to redirect to blank if there is no matching route, and there is not one for test...

guessing you want to set the base href in your build command...

ng build --prod --baseHref=test

docs: https://angular.io/cli/build

you can set the same in ng serve if you're trying to run this as a dev server. but that seems redundant.

Sign up to request clarification or add additional context in comments.

1 Comment

Look at my last line, I am using baseHref
0
+50

Try directing through router class. After setting in component; .navigate to me it happend with wrong name.

1 Comment

can you share code? this is not understandable, what exactly u want to say

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.