0

I want to change the base url

when load the application url is http://localhost:4200/#/ I want to change this to http://localhost:4200/carrom/.

For doing this I changed base url to then loading url is http://localhost:4200/carrom#/

How can I change this to http://localhost:4200/carrom...but the images and assets are not loading

For doing this I changed base url to then loading url is http://localhost:4200/carrom#/

1
  • The problem is how you define the "src" of your images.the correct is, see that there's no "./" or "../.../" : <img src="assets/images/img1.jpg"> Commented Feb 29, 2024 at 7:29

1 Answer 1

0

From what I could make out, you could do either of the below.

  1. Set up routes so that the base url "/" loads the carrom component.

    const routes: Routes = [{ path: '', component: CarromComponent }, { path: 'home', component: HomeComponent }, { path: '**', component: PageNotFoundComponent }, // Wildcard route for a 404 page ];

Or call navigate on HomeComponent load

import { Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  ...
})
export class HomeComponent {

  constructor(private router: Router){
   this.navigate()
  }

  navigate(){
    this.router.navigate(['/carrom']) // assuming this the route of the carrom component
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

but how do we inject router object in Home Component
You won't be adding routing to the page, but the entire application. samjulien.com/add-routing-existing-angular-project Just thought of another hacky way of doing it, look for <app-component></app-component> and replace it with <carrom-component></carrom-component>. This is not the right way of doing it, but will achieve what you want temporarily

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.