在 Angular JS 项目中更改基本 url 时未加载图像

问题描述 投票:0回答:1

我想更改基本网址

加载时,应用程序 URL 为 http://localhost:4200/#/ 我想将其更改为 http://localhost:4200/carrom/。

为此,我将基本 url 更改为然后加载 url 为 http://localhost:4200/carrom#/

如何将其更改为 http://localhost:4200/carrom...但图像和资源未加载

为此,我将基本 url 更改为然后加载 url 为 http://localhost:4200/carrom#/

angular angularjs typescript angularjs-routing
1个回答
0
投票

据我所知,您可以执行以下任一操作。

  1. 设置路由,以便基本 URL“/”加载 carrom 组件。

    常量路线:路线= [{ 小路: '', 组件:CarromComponent }, { 路径:'家', 组件:HomeComponent }, { 小路: '**', 组件:PageNotFoundComponent }, // 404页面的通配符路由 ];

或者在 HomeComponent 加载时调用导航

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
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.