Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Angular 2中资产的URL_Angularjs_Angular - Fatal编程技术网

Angularjs Angular 2中资产的URL

Angularjs Angular 2中资产的URL,angularjs,angular,Angularjs,Angular,我有tips.pdf,我想住在/tips 当用户手动键入/tips时,我希望它重定向到/tips.pdf,最好是在新选项卡中 当我更新我的路由模块时,我得到错误:无法匹配任何路由。URL段:“提示” const ROUTES: Routes = [ { path: '', redirectTo: '/home', pathMatch: 'full' }, { path: 'home', component: HomeComponent }, { pat

我有
tips.pdf
,我想住在
/tips

当用户手动键入
/tips
时,我希望它重定向到
/tips.pdf
,最好是在新选项卡中

当我更新我的路由模块时,我得到
错误:无法匹配任何路由。URL段:“提示”

const ROUTES: Routes = [
  {
    path: '', redirectTo: '/home', pathMatch: 'full'
  },
  {
    path: 'home', component: HomeComponent
  },
  {
    path: 'fun', component: FunComponent
  },
  {
    path: 'tips', redirectTo: '../assets/pdfs/tips.pdf', pathMatch: 'full'
  }
]

这是因为我没有组件吗?显然,我不想只为资产文件夹中的固定pdf创建组件。

这是因为您没有任何路由加工“../assets/pdfs/tips.pdf”。第一个重定向有效,因为home与
路由中的第二个条目相匹配


您不需要Angular这样做,您需要在服务器配置中添加重定向。

我认为Angular无法做到这一点

您可以尝试的一件事是创建一个虚拟组件,使用
window.open
打开url

{
    path: 'tips', component: FilOpenerComponent 
}

export class FilOpenerComponent {
    constructor(private router: Router) {
       window.open("../assets/pdfs" + this.router.url + ".pdf");
    }
}

您还可以使用查询参数进一步概括此组件,以准确地知道在何处查找文件。

当前路径或重定向路径都应该有一个角度为的组件。
因此,正如其中一个答案中提到的,逻辑必须添加到组件中

我认为这种重定向需要由服务器完成我知道如何在服务器上完成,但我想知道是否有一种方法可以在