【问题标题】:Ember and htaccess for RefreshingEmber 和 htaccess 用于刷新
【发布时间】:2025-12-28 12:30:11
【问题描述】:

我正在开发一个 Ember 2.6 应用程序,但在刷新页面时遇到了问题。这看起来是一个常见问题,所以我找到并更新了我的.htaccess 文件,如下所示:

Options FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

因此,每当我刷新以下 URL 时,这都会起作用:http://danyuschick.com/projects

但是,每当我刷新时它都不会加载:http://danyuschick.com/projects/14

这是我的路由器:

Router.map(function() {
  this.route('about');
  this.route('blogs');
  this.route('projects', function() {
      this.route('index', { path: '/' });
      this.route('project', { path: '/:project_id' });
  });
  this.route('error', { path: '*path' });
  this.route('loading');
});

还有我定义模型的路线

model(params) {
    return this.store.findRecord('projects', params.project_id);
}

我不确定这个更新需要在哪里进行,htaccess 或我的路由器或什么。

【问题讨论】:

  • 试试 this.store.findRecord('project', params.project_id); - ember-data 默认情况下它会复数模型和数据请求
  • 不走运,@kumkanillam。刷新时没有加载任何文件或样式的结果仍然相同。虽然我可以看到没有控制台错误,
  • 虽然我可以说刷新后 params.project_id 仍然正确填充。
  • 刷新时 projects/index.hbs 将被 projects/14 覆盖 ..所以你需要将 projects/index.hbs 移动到 projects.hbs ..如果你不明白,我会提供样品旋转...
  • 谢谢,@kumkanillam。我想我需要一个例子。现在 app/projects.hbs 只是我的 {{liquid-outlet}} 而我的 projects/index.hbs 是 {{component 'list' model=model}}。所以我不确定这将如何重新设计。

标签: javascript .htaccess ember.js firebase ember-cli


【解决方案1】:

如果你试试这个,它应该可以工作:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]

它的作用是检查%{REQUEST_FILENAME} 是否是一个有大小的文件,或者是一个符号链接,还是一个目录。如果没有,它会将请求重写为 index.html

【讨论】:

  • 没有变化。我仍然可以刷新 /projects 但不能刷新 /projects/14。