【问题标题】:Angular (6) view button (click) function redirect to Laravel(5.5) Back-end ViewAngular(6)视图按钮(点击)功能重定向到Laravel(5.5)后端视图
【发布时间】:2019-08-09 15:20:04
【问题描述】:

我希望当我单击 Angular 前端按钮时重定向到 Laravel 后端视图。我是 angular 新手。这是我尝试做的。请帮助我。

frontend.component.html

<button type="button" (click)="userDetailsEdit()">Edit Details</button>

frontend.component.ts

   userDetailsEdit() {
    alert('Its Working');
    this.authService.goToBreweryBarBackend();
}

auth.service.ts

 goToBreweryBarBackend() {
              const accessToken = JSON.parse(localStorage.getItem('access_token'));
              headers.append('Content-Type', 'application/json');
              this.http.get(this.url.LaravelURL + 'api/goToBreweryBarBackend', { headers: new Headers({ 'Authorization': 'Bearer ' + accessToken }) });

api.php

Route::get('/goToBreweryBarBackend', ['uses' => 'Homecontroller@index']);

HomeController.php

public function index()
{
    return view('home');
}

【问题讨论】:

  • 控制台有错误吗?
  • 没有。没有错误
  • “重定向”是什么意思?在您的代码中,您试图将呈现的 HTML 返回到 API 请求。这是你想要做的吗?或者你想要完全重定向到应用程序的 Laravel 端?
  • 我认为这会有所帮助:stackoverflow.com/questions/34338440/…
  • Laravel 使用“会话”守卫作为 web 的默认值。也许您可以实现一个从 URL 获取访问令牌并手动验证用户的中间件。因此,当您重定向用户时,您可以通过第一次重定向传递访问令牌。

标签: angular laravel redirect angular6 backend


【解决方案1】:
userDetailsEdit() {
    window.location.href = 'http://localhost:8000/intro'; 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多