无法删除Aurelia路由的前一个主题标签

时间:2017-08-24 15:05:13

标签: aurelia jspm

我遇到了一个我似乎无法解决的问题。 应该可以通过执行RouterConfiguration -> Options-> Push State

中提供的步骤来删除路由中的前一个hashtag

我已执行了所有这些步骤,请参阅下面的代码。

app.ts RouterConfiguration选项

public configureRouter(config: RouterConfiguration, router: Router) {
    config.options.pushState = true;
    config.options.root = '/';
    config.map([
        {
            route: 'login',
            name: 'login',
            moduleId: 'pages/auth/login',
            nav: false,
            title: 'Login',
            settings: {
                allow_anonymous: true
            }
        }
    ]);
    ...

index.html头

<head>
  <meta charset="utf-8">
  <base href="/">
  ...

config.js

System.config({
  baseURL: "/",
  ...

我的登录路线仍然只能使用localhost:9000/#/login而无法找到localhost:9000/login。 我也试过在一个新的Aurelia JSPM骨架应用程序中实现它无济于事......

知道为什么会发生这种情况以及我可能做错了什么?

2 个答案:

答案 0 :(得分:1)

对于BrowserSync(如@Bryandh所述),您需要将其配置为始终回退到index.html。根据您的项目,您可能需要更改一些任务文件(例如,Aurelia中使用的Gulp服务任务)。

作为一个例子,我参加了Aurelia的骨架导航项目。它有一个子目录skeleton-esnext,它使用Gulp和JSPM来运行应用程序。在文件build/tasks/serve.js中是serve任务,需要按如下方式进行调整:

var historyFallback = require('connect-history-api-fallback');

gulp.task('serve', ['build'], function(done) {
  browserSync({
    online: false,
    open: false,
    port: 9000,
    server: {
      baseDir: ['.'],
      middleware: [function(req, res, next) {
        res.setHeader('Access-Control-Allow-Origin', '*');
        next();
      }, historyFallback()]
    }
  }, done);
});

重要的部分是historyFallback()中间件。这是BrowserSync自动提供的。如果您现在通过此任务(gulp servegulp watch)为您的应用提供服务,则可以直接访问您的路线,例如http://localhost:9000/users。当你被引导到index.html时,将不再有404引导Aurelia并处理路线/users

答案 1 :(得分:0)

对于我的视图被动态加载到路由器视图容器中,以索引为根,我能够使我的项目的URL看起来如下(我相信你要求的):

  • handler.postDelayed(new Runnable() { @Override public void run() { GraphRequest nextResultsRequests = lastGraphResponse.getRequestForPagedResults(GraphResponse.PagingDirection.NEXT); if (nextResultsRequests != null) { nextResultsRequests.setCallback(request.getCallback()); lastGraphResponse = nextResultsRequests.executeAndWait(); } } }, DELAY_IN MILLISECONDS);
  • http://localhost:2112/
  • http://localhost:2112/jobs

我不需要改变您共享的代码,以使其工作。我做的第一件事是在我的根html文件中建立一个基本引用。  对我来说,这是 index.html

http://localhost:2112/discussion

然后,我将推送状态设置为<base href="/" />方法

内的true
configureRouter()